:root {
  color-scheme: dark;
  --card-width: clamp(84px, 13vw, 136px);
  --bg: #111318;
  --panel: #1b2029;
  --panel-2: #242b36;
  --line: #343d4c;
  --text: #f5f7fb;
  --muted: #9da7b8;
  --gold: #f1c75b;
  --spade: #8fb4ff;
  --heart: #ff6b88;
  --club: #65d58a;
  --diamond: #f6a04d;
  --danger: #ff5f73;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 25% 15%, rgba(143, 180, 255, 0.14), transparent 30%),
    linear-gradient(135deg, #101218 0%, #18202a 50%, #12151b 100%);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible {
  border-color: var(--gold);
  outline: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app {
  width: min(1180px, calc(100vw - 24px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0 max(72px, calc(env(safe-area-inset-bottom) + 72px));
}

.screen {
  min-height: calc(100vh - 48px);
}

.hidden {
  display: none !important;
}

.title-screen {
  display: grid;
  align-content: center;
  gap: 36px;
}

.title-copy h1 {
  margin: 0;
  font-size: clamp(4rem, 15vw, 11rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.kicker,
.subtitle,
.high-score {
  color: var(--muted);
  font-weight: 700;
}

.subtitle {
  max-width: 42rem;
  font-size: 1.1rem;
}

.high-score strong {
  color: var(--gold);
  font-size: 1.4rem;
}

.title-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 180px));
  gap: 12px;
}

.mute-toggle {
  width: fit-content;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.mute-toggle input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--gold);
  cursor: pointer;
}

.mute-toggle:has(input:focus-visible) {
  color: var(--text);
  outline: 2px solid var(--gold);
  outline-offset: 6px;
  border-radius: 6px;
}

.primary-button {
  background: var(--gold);
  color: #191611;
  border-color: transparent;
}

.game-screen {
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-content: start;
  gap: 14px;
  position: relative;
}

.game-header,
.sub-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.game-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
}

.game-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.game-nav {
  display: flex;
  justify-content: flex-start;
}

.game-nav:empty {
  display: none;
}

.floating-title-button {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  z-index: 100;
  display: block;
  min-width: 76px;
  min-height: 42px;
  padding: 0 10px;
  font-size: 0.8rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.icon-button {
  min-width: 78px;
  padding: 0 12px;
}

.stat {
  min-width: 112px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(27, 32, 41, 0.82);
}

.game-header #home-button {
  display: none;
}

.stat span,
.slot-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 1.35rem;
}

.used-panel {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(27, 32, 41, 0.82);
}

.used-grid {
  display: grid;
  gap: 8px;
}

.used-row {
  display: grid;
  grid-template-columns: 34px repeat(13, minmax(34px, 1fr));
  gap: 6px;
  align-items: center;
}

.used-suit {
  font-weight: 900;
  text-align: center;
}

.used-card {
  min-height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #151922;
  font-size: 0.78rem;
  font-weight: 900;
}

.used-card.used {
  color: #5f6878;
  background: #222631;
  text-decoration: line-through;
}

.table-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 4vw, 56px);
  padding: 4px 0 2px;
}

.table-button {
  width: clamp(70px, 10vw, 104px);
  align-self: center;
}

.slot {
  width: var(--card-width);
  display: grid;
  gap: 8px;
  justify-items: center;
}

.card {
  width: var(--card-width);
  aspect-ratio: 0.72;
  border: 2px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  position: relative;
  background: #f7f4ea;
  color: #12151b;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
  font-weight: 1000;
  user-select: none;
}

.card.empty {
  background: rgba(27, 32, 41, 0.9);
  color: var(--muted);
}

.card.joker {
  background: linear-gradient(145deg, #fff8d8, #ffd9e2);
  color: #101218;
}

.card.joker .rank {
  width: calc(100% - 18px);
  text-align: center;
  font-size: clamp(1.3rem, 3vw, 2.5rem);
}

.card .rank {
  font-size: clamp(2.1rem, 5vw, 4rem);
  line-height: 1;
}

.card .suit {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: clamp(1.25rem, 3vw, 2rem);
}

.card .corner {
  position: absolute;
  left: 8px;
  top: 7px;
  font-size: 0.82rem;
  font-weight: 900;
}

.hand {
  display: grid;
  grid-template-columns: repeat(5, minmax(64px, 136px));
  justify-content: center;
  gap: clamp(8px, 2vw, 18px);
  margin-top: 2px;
}

.hand .card {
  border-color: rgba(255, 255, 255, 0.26);
}

.hand .card.playable {
  border-color: var(--gold);
  box-shadow:
    0 0 0 3px rgba(241, 199, 91, 0.24),
    0 18px 40px rgba(0, 0, 0, 0.32);
}

.hand .card.playable::before,
.hand .card.playable::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  height: 5px;
  border-radius: 999px;
  background: var(--gold);
}

.hand .card.playable::before {
  top: 10px;
}

.hand .card.playable::after {
  bottom: 10px;
}

.hand .card.unplayable {
  cursor: default;
}

.hand .card.playable:hover {
  transform: translateY(-8px);
  box-shadow:
    0 0 0 4px rgba(241, 199, 91, 0.34),
    0 24px 48px rgba(0, 0, 0, 0.4);
}

.message-area {
  position: fixed;
  left: 18px;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
  z-index: 10;
}

.message {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  background: rgba(20, 24, 32, 0.95);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-weight: 700;
}

.list-screen {
  display: grid;
  align-content: start;
  gap: 18px;
}

.sub-header h2 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 4rem);
}

.list-grid,
.data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.achievement,
.data-item {
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(27, 32, 41, 0.88);
}

.achievement.unlocked {
  border-color: rgba(241, 199, 91, 0.8);
}

.achievement h3,
.data-item h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.achievement p,
.data-item p {
  margin: 0;
  color: var(--muted);
}

.spades {
  color: var(--spade);
}

.hearts {
  color: var(--heart);
}

.clubs {
  color: var(--club);
}

.diamonds {
  color: var(--diamond);
}

@media (max-width: 720px) {
  :root {
    --card-width: clamp(70px, calc((100vw - 56px) / 5), 136px);
  }

  .app {
    width: min(100vw - 16px, 1180px);
    padding: 8px 0 max(112px, calc(env(safe-area-inset-bottom) + 112px));
  }

  .screen {
    min-height: calc(100vh - 26px);
  }

  body:has(#title-screen:not(.hidden)) .app {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .title-screen {
    align-content: start;
    gap: 24px;
    min-height: calc(100svh - 16px);
    padding-top: clamp(12px, 5svh, 40px);
  }

  .title-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .game-header {
    display: flex;
    align-items: stretch;
    gap: 8px;
  }

  .game-stats {
    display: flex;
    gap: 8px;
  }

  .game-header .icon-button {
    min-width: 76px;
    padding: 0 10px;
    font-size: 0.8rem;
  }

  .game-header .stat {
    flex: 1 1 0;
    min-width: 0;
    padding: 7px 8px;
  }

  .game-header .stat strong {
    font-size: 1.15rem;
  }

  .used-row {
    grid-template-columns: 26px repeat(13, minmax(20px, 1fr));
    gap: 3px;
  }

  .used-card {
    min-height: 24px;
    font-size: 0.65rem;
  }

  .game-screen {
    gap: 10px;
  }

  .used-panel {
    padding: 8px;
  }

  .used-grid {
    gap: 5px;
  }

  .hand {
    grid-template-columns: repeat(5, minmax(54px, 1fr));
    margin-top: 0;
  }

  .card {
    width: var(--card-width);
  }

  .table-area {
    display: grid;
    grid-template-columns: minmax(52px, 70px) var(--card-width) var(--card-width) minmax(52px, 70px);
    gap: clamp(12px, 4vw, 22px);
    justify-items: center;
    padding: 2px 0 0;
  }

  .table-button {
    width: 100%;
    min-height: 38px;
    padding: 0 6px;
    font-size: 0.78rem;
  }
}
