:root {
  color-scheme: dark;
  --bg: #102014;
  --panel: #0e4628;
  --panel-soft: #17643b;
  --line: rgba(0, 0, 0, 0.24);
  --text: #f3f5ef;
  --muted: #c7d4c8;
  --pink: #f5f5ef;
  --green: #101010;
  --button: #2ea35e;
  --button-dark: #1d6d3d;
  --button-light: #57c57f;
  --button-text: #f6fff7;
  --board-grid-size: min(calc(100vw - 52px), 560px);
  --cell-size: calc((var(--board-grid-size) - 8px) / 9);
  --board-frame-size: calc(var(--board-grid-size) + 20px);
  --tile-grid: #111214;
  --tile-bg: #1a643a;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top, rgba(63, 138, 85, 0.28), transparent 30%),
    linear-gradient(180deg, #17643b 0%, #133720 24%, var(--bg) 100%);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

button {
  appearance: none;
  border: 1px solid rgba(6, 27, 13, 0.5);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--button-light) 0%, var(--button) 46%, var(--button-dark) 100%);
  color: var(--button-text);
  min-height: 50px;
  padding: 0 18px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -2px 0 rgba(0, 0, 0, 0.22),
    0 7px 16px rgba(0, 0, 0, 0.22);
}

button.secondary {
  background: linear-gradient(180deg, #3f8f5a 0%, #2a6f44 50%, #184529 100%);
  color: #edf7ef;
}

button:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -1px 0 rgba(0, 0, 0, 0.24),
    0 3px 8px rgba(0, 0, 0, 0.18);
}

.app {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    16px
    max(18px, env(safe-area-inset-bottom));
}

.intro-screen,
.game-screen,
.layout,
.winner-panel {
  width: min(100%, 1040px);
  margin-inline: auto;
}

.is-hidden {
  display: none !important;
}

.intro-screen {
  min-height: calc(100dvh - max(36px, env(safe-area-inset-top)) - max(36px, env(safe-area-inset-bottom)));
  display: grid;
  place-items: center;
}

.intro-card {
  width: min(100%, 420px);
  text-align: center;
}

.intro-logo {
  display: block;
  width: min(100%, 192px);
  height: auto;
  margin: 0 auto;
}

.intro-logo-link,
.game-logo-link {
  display: inline-block;
}

.intro-text {
  margin: 20px auto 24px;
  max-width: 24rem;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.45;
}

.mode-actions {
  display: grid;
  gap: 12px;
}

.online-mode-link {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.color-card {
  width: min(100%, 440px);
}

.color-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin: 4px auto 24px;
}

.color-choice {
  min-height: 0;
  padding: 16px 12px 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(38, 115, 67, 0.98) 0%, rgba(17, 73, 42, 0.98) 100%);
  display: grid;
  gap: 8px;
  justify-items: center;
  position: relative;
  overflow: hidden;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease;
}

.color-choice::after {
  content: "";
  position: absolute;
  inset: -30% auto auto -28%;
  width: 65%;
  height: 170%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0) 70%);
  transform: rotate(18deg);
  pointer-events: none;
}

.color-choice-white {
  border-color: rgba(255, 255, 255, 0.48);
  background: linear-gradient(180deg, #fbfbf6 0%, #e9e8de 100%);
}

.color-choice-black {
  border-color: rgba(255, 255, 255, 0.14);
  background: linear-gradient(180deg, #2f2f2f 0%, #090909 100%);
}

.color-choice-canvas {
  display: block;
  width: min(100%, 118px);
  aspect-ratio: 1 / 1;
  position: relative;
  z-index: 1;
  border-radius: 0;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.color-choice span {
  font-weight: 800;
  position: relative;
  z-index: 1;
}

.color-choice-kicker {
  font-size: 0.58rem;
  letter-spacing: 0.24em;
  opacity: 0.76;
}

.color-choice-name {
  font-size: 1rem;
  letter-spacing: 0.2em;
}

.color-choice-note {
  font-size: 0.58rem;
  letter-spacing: 0.2em;
  opacity: 0.8;
}

.color-choice-white .color-choice-kicker,
.color-choice-white .color-choice-name,
.color-choice-white .color-choice-note {
  color: #101010;
}

.color-choice-black .color-choice-kicker,
.color-choice-black .color-choice-name,
.color-choice-black .color-choice-note {
  color: #f5f5ef;
}

.color-choice.is-selected {
  animation: colorChoicePulse 1s ease-in-out infinite alternate;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -2px 0 rgba(0, 0, 0, 0.22),
    0 0 0 2px rgba(255, 255, 255, 0.18),
    0 12px 24px rgba(0, 0, 0, 0.24);
}

.color-choice-white.is-selected {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.26),
    inset 0 -2px 0 rgba(0, 0, 0, 0.16),
    0 0 0 2px rgba(255, 255, 255, 0.22),
    0 0 28px rgba(255, 255, 255, 0.14),
    0 12px 24px rgba(0, 0, 0, 0.2);
}

.color-choice-black.is-selected {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3),
    0 0 0 2px rgba(255, 255, 255, 0.16),
    0 0 28px rgba(0, 0, 0, 0.26),
    0 12px 24px rgba(0, 0, 0, 0.24);
}

.color-helper {
  margin: -4px auto 18px;
  max-width: 22rem;
  color: rgba(243, 245, 239, 0.82);
  font-size: 0.74rem;
  line-height: 1.45;
  letter-spacing: 0.04em;
}

@keyframes colorChoicePulse {
  0% {
    transform: translateY(0) scale(1);
  }

  100% {
    transform: translateY(-1px) scale(1.03);
  }
}

.game-topbar {
  width: min(100%, 1040px);
  margin: 0 auto 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.game-logo {
  display: block;
  width: 154px;
  height: auto;
}

.turn-pill {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid rgba(6, 27, 13, 0.5);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(46, 163, 94, 0.98) 0%, rgba(23, 100, 59, 0.98) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -2px 0 rgba(0, 0, 0, 0.22),
    0 7px 16px rgba(0, 0, 0, 0.22);
}

.panel-label,
.winner-label {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.turn-pill strong {
  display: block;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #f4fff6;
}

.layout {
  display: grid;
  gap: 18px;
  justify-items: center;
}

.board-panel,
.sidebar {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(25, 96, 56, 0.98) 0%, rgba(12, 58, 33, 0.98) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.24),
    0 14px 30px rgba(0, 0, 0, 0.22);
}

.board-panel {
  padding: 10px;
  width: var(--board-frame-size);
  max-width: 100%;
  overflow: visible;
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset -18px -18px 32px rgba(0, 0, 0, 0.14),
    inset 18px 18px 26px rgba(255, 255, 255, 0.03),
    18px 22px 32px rgba(0, 0, 0, 0.26);
}

.board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 1px;
  justify-content: center;
  width: var(--board-grid-size);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin-inline: auto;
  padding: 0;
  background: #3b413b;
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -1px 0 rgba(0, 0, 0, 0.16);
}

.board-cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  min-height: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  outline: 0;
}

.board-cell.is-valid {
  outline: 0;
}

.board-cell.is-preview-cell {
  outline: 2px solid rgba(245, 245, 239, 0.42);
  outline-offset: 0;
}

.board-cell:focus,
.board-cell:focus-visible {
  outline: 0;
}

.board-cell.is-winning {
  outline: 0;
}

.board-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.play-stack {
  display: grid;
  gap: 10px;
  width: 100%;
  justify-items: center;
}

.play-stack.is-turn-swapping #topHandCard {
  animation: handTopShift 420ms cubic-bezier(0.22, 0.8, 0.28, 1);
}

.play-stack.is-turn-swapping #bottomHandCard {
  animation: handBottomShift 420ms cubic-bezier(0.22, 0.8, 0.28, 1);
}

@keyframes handTopShift {
  0% {
    transform: translateY(0);
    opacity: 1;
  }

  45% {
    transform: translateY(16px) scale(0.985);
    opacity: 0.7;
  }

  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes handBottomShift {
  0% {
    transform: translateY(0);
    opacity: 1;
  }

  45% {
    transform: translateY(-16px) scale(0.985);
    opacity: 0.7;
  }

  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

.sidebar {
  padding: 12px 16px 16px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.hand-card {
  padding: 10px 12px;
  width: 100%;
  border-radius: 9px;
}

.hand-card.is-white-hand {
  background: #ffffff;
}

.hand-card.is-black-hand {
  background: #111111;
}

.hand-card.is-active {
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 10px 22px rgba(0, 0, 0, 0.12);
}

.hand-card .panel-label {
  display: none;
}

.tile-rack {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 22px;
  align-items: center;
  justify-items: center;
}

.tile-slot {
  width: min(100%, 72px);
  aspect-ratio: 1 / 1;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  border: 1px solid rgba(6, 27, 13, 0.35);
  background: #1a643a;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -1px 0 rgba(0, 0, 0, 0.22);
}

.tile-slot.is-empty {
  background:
    linear-gradient(180deg, rgba(38, 78, 53, 0.78) 0%, rgba(18, 48, 30, 0.82) 100%);
  opacity: 0.45;
}

.tile-slot.is-selected {
  border-color: rgba(255, 255, 255, 0.32);
  animation: selectedTileBreath 1.25s ease-in-out infinite;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 0 0 2px rgba(255, 255, 255, 0.16);
}

.tile-slot.is-turn {
  cursor: pointer;
}

.tile-slot.is-turn:not(.is-empty):not(.is-disabled) {
  border-color: rgba(255, 255, 255, 0.22);
}

.tile-slot.is-disabled {
  cursor: default;
  opacity: 0.72;
}

.tile-slot-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 0;
}

@keyframes selectedTileBreath {
  0%,
  100% {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.18),
      0 0 0 2px rgba(255, 255, 255, 0.14),
      0 0 0 rgba(255, 255, 255, 0);
    transform: translateY(0);
  }

  50% {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.24),
      0 0 0 2px rgba(255, 255, 255, 0.28),
      0 0 18px rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
  }
}

.hand-hint {
  display: none;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 16px;
}

.game-bottom-actions {
  width: min(100%, 1040px);
  margin: 4px auto 0;
}

.game-bottom-actions button {
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}

.game-bottom-actions button:active {
  transform: none;
  box-shadow: none;
}

.status-text {
  min-height: 2.8em;
  margin: 0 2px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: center;
}

.winner-panel {
  margin-top: 18px;
  padding: 18px 16px 0;
  text-align: center;
}

.winner-panel h2 {
  margin: 8px 0 16px;
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  line-height: 1;
  letter-spacing: 0.1em;
}

#turnLabel[data-color="P"],
#winnerText[data-color="P"] {
  color: var(--pink);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.16);
}

#turnLabel[data-color="V"],
#winnerText[data-color="V"] {
  color: var(--green);
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.18);
}

@media (min-width: 560px) {
  :root {
    --board-grid-size: min(58vw, 62vh, 560px);
  }

  .layout {
    grid-template-columns: 1fr;
    align-items: center;
    justify-content: center;
  }

  .play-stack {
    display: grid;
    grid-template-columns: 84px var(--board-frame-size) 84px;
    gap: clamp(12px, 2.4vw, 26px);
    align-items: center;
    justify-content: center;
    width: 100%;
  }

  #topHandCard {
    grid-column: 1;
  }

  .board-panel {
    grid-column: 2;
  }

  #bottomHandCard {
    grid-column: 3;
  }

  .hand-card {
    width: 84px;
    min-height: var(--board-frame-size);
    padding: 14px 6px 10px;
    display: grid;
    align-content: start;
  }

  .hand-card .panel-label {
    display: block;
    min-height: 2.4em;
    margin: 0 auto;
    max-width: 64px;
    color: currentColor;
    font-size: 0.52rem;
    line-height: 1.2;
    letter-spacing: 0.12em;
    text-align: center;
  }

  .hand-card.is-white-hand {
    color: #111111;
  }

  .hand-card.is-black-hand {
    color: #f5f5ef;
  }

  .tile-rack {
    grid-template-columns: 1fr;
    grid-auto-rows: 46px;
    gap: 24px;
    margin-top: clamp(28px, 5vh, 56px);
  }

  .tile-slot {
    width: 46px;
  }

  .sidebar {
    width: min(100%, var(--board-frame-size));
    padding-top: 14px;
  }
}

@media (min-width: 860px) {
  :root {
    --board-grid-size: min(54vw, 70vh, 640px);
  }

  .play-stack {
    grid-template-columns: 116px var(--board-frame-size) 116px;
    gap: clamp(22px, 4vw, 52px);
  }

  .hand-card {
    width: 116px;
    padding: 12px 10px;
  }

  .hand-card .panel-label {
    max-width: 86px;
    font-size: 0.62rem;
  }

  .tile-rack {
    grid-auto-rows: 60px;
    gap: 30px;
    margin-top: clamp(34px, 6vh, 72px);
  }

  .tile-slot {
    width: 60px;
  }
}

@media (max-width: 480px) {
  :root {
    --board-grid-size: min(calc(100vw - 36px), 360px);
  }

  .intro-logo {
    width: min(100%, 164px);
  }

  .intro-text {
    font-size: 0.9rem;
  }

  .color-options {
    gap: 12px;
    margin-bottom: 18px;
  }

  .color-choice {
    padding: 12px 8px 10px;
    border-radius: 16px;
    gap: 8px;
  }

  .color-choice-canvas {
    width: min(100%, 94px);
  }

  .color-choice-kicker {
    font-size: 0.52rem;
    letter-spacing: 0.2em;
  }

  .color-choice-name {
    font-size: 0.86rem;
    letter-spacing: 0.16em;
  }

  .color-choice-note {
    font-size: 0.5rem;
    letter-spacing: 0.14em;
  }

  .color-helper {
    margin-bottom: 16px;
    font-size: 0.68rem;
  }

  .game-logo {
    width: 132px;
  }

  .turn-pill {
    min-height: 36px;
    padding: 7px 12px;
  }

  .turn-pill strong {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
  }

  .app {
    padding:
      max(12px, env(safe-area-inset-top))
      10px
      max(12px, env(safe-area-inset-bottom));
  }

  .game-topbar {
    margin-bottom: 34px;
  }

  .layout {
    gap: 10px;
  }

  .play-stack {
    gap: 7px;
  }

  .board-panel {
    padding: 8px;
  }

  .sidebar {
    padding: 8px 10px 10px;
  }

  .hand-card {
    padding: 8px 10px;
  }

  .tile-rack {
    gap: 14px;
  }

  .tile-slot {
    width: min(100%, 56px);
    transform: none;
  }

  .tile-slot-canvas {
    border-radius: 0;
  }

  .button-row {
    margin-top: 10px;
  }

  .game-bottom-actions {
    margin-top: 4px;
  }

  .status-text {
    min-height: 2.2em;
    font-size: 0.78rem;
    line-height: 1.35;
  }
}
