:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #5d6a65;
  --panel: #f7f4ee;
  --surface: rgba(255, 252, 246, 0.86);
  --card: #fffaf1;
  --button: #fffdf8;
  --line: #d8d0c3;
  --red: #b54635;
  --yellow: #d5a93b;
  --blue: #1d6f8f;
  --green: #3f7f4d;
  --wild: #202522;
  --board: #26352f;
  --tile: #fbfaf6;
  --focus: #e9b44c;
  --shadow: rgba(42, 35, 24, 0.13);
  --page:
    linear-gradient(135deg, rgba(29, 111, 143, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(181, 70, 53, 0.13), transparent 30%),
    #ebe4d8;
}

html.dark-theme,
body.dark-theme {
  color-scheme: dark;
  --ink: #f1eee7;
  --muted: #c2bbb0;
  --panel: #1f2926;
  --surface: rgba(28, 35, 32, 0.9);
  --card: #26312d;
  --button: #202a27;
  --line: #48524d;
  --board: #111a18;
  --tile: #f4efe4;
  --focus: #f0bc55;
  --shadow: rgba(0, 0, 0, 0.32);
  --page:
    linear-gradient(135deg, rgba(29, 111, 143, 0.2), transparent 34%),
    linear-gradient(315deg, rgba(181, 70, 53, 0.16), transparent 30%),
    #141917;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button {
  font: inherit;
}

button:disabled {
  cursor: default;
}

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0 0;
}

.site-nav a {
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  font-size: 1.1rem;
  font-weight: 950;
}
.brand-mark img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nav-links a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #bfb5a4;
  border-radius: 8px;
  background: var(--button);
  padding: 0 12px;
  font-weight: 800;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(233, 180, 76, 0.22);
}

.game-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0 28px;
}

.scorebar,
.topbar,
.workspace,
.move-log-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 22px 52px var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(210px, 0.8fr) minmax(480px, 1.8fr) auto;
  align-items: stretch;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 8px 8px 0 0;
}

.brand-block {
  display: grid;
  align-content: center;
}

.brand-block h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5vw, 3.7rem);
  line-height: 0.95;
}

.rules-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.rules-summary div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.rules-summary span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.theme-toggle {
  align-self: start;
}

.scorebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-top: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
}

.score-pair {
  display: flex;
  gap: 10px;
}

.score-card {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 10px;
  min-width: 92px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.score-card span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-weight: 900;
}

.score-card strong {
  font-size: 1.7rem;
}

.turn-card span {
  background: var(--board);
}

.deck-score span {
  background: var(--blue);
}

.orbit-score span {
  background: var(--red);
}

.hand-score span {
  background: var(--green);
}

.workspace {
  display: grid;
  grid-template-columns: 250px 1fr;
  grid-template-areas: "panel board";
  min-height: 700px;
  border-top: 0;
}

.panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.current-card-panel,
.status-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.preview-card {
  width: min(150px, 100%);
  aspect-ratio: 5 / 6;
  margin: 10px auto 0;
}

.action-group {
  display: grid;
  gap: 8px;
}

.action-button,
.reset-button,
.small-button {
  min-height: 46px;
  border: 1px solid #bfb5a4;
  border-radius: 8px;
  background: var(--button);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  text-align: left;
}

.action-button:hover,
.reset-button:hover,
.small-button:hover,
.space.legal:hover {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(233, 180, 76, 0.22);
}

.action-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: rgba(23, 32, 29, 0.1);
  font-size: 1.1rem;
}

.status-card strong {
  font-size: 1.55rem;
}

.legend-card {
  display: grid;
  gap: 8px;
}

.control-card {
  display: grid;
  gap: 8px;
}

.control-card label,
.control-card span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.control-card select {
  min-height: 40px;
  width: 100%;
  border: 1px solid #bfb5a4;
  border-radius: 8px;
  background: var(--button);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  padding: 0 10px;
}

.hand-card-panel {
  display: grid;
  gap: 10px;
  justify-self: stretch;
  width: 100%;
  max-width: 860px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.hand-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.hand-header .eyebrow {
  margin-bottom: 0;
}

.hand-header span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.hand {
  display: flex;
  flex-flow: row nowrap;
  gap: 10px;
  align-items: stretch;
  max-width: 100%;
  padding: 2px 2px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-color: var(--focus) var(--panel);
}

.hand-card {
  flex: 0 0 88px;
  width: 88px;
  aspect-ratio: 5 / 6;
  min-height: 0;
  padding: 5px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--button);
  cursor: pointer;
}

.hand-card.selected {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(233, 180, 76, 0.24);
}

.hand-card:disabled {
  opacity: 0.45;
}

.legend-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.swatch {
  height: 28px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 8px;
}

.reset-button {
  margin-top: auto;
}

.board-wrap {
  grid-area: board;
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 18px;
  padding: 24px;
  min-width: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(11, minmax(38px, 58px));
  grid-template-rows: repeat(11, minmax(46px, 70px));
  gap: 5px;
  max-width: 100%;
  padding: 12px;
  border-radius: 8px;
  background: var(--board);
  overflow: auto;
}

.space {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  cursor: default;
}

.space.orbit-active {
  background: rgba(255, 255, 255, 0.12);
}

.space.legal {
  border-color: var(--focus);
  cursor: pointer;
}

.space.hint {
  animation: hintPulse 0.8s ease-in-out infinite alternate;
}

.space.blocked {
  opacity: 0.36;
}

.deck-space {
  display: grid;
  place-items: center;
  border-color: rgba(255, 255, 255, 0.32);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.12), transparent),
    var(--wild);
  color: white;
  font-weight: 900;
}

.deck-space span {
  display: grid;
  width: 70%;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
}

.orbit-card {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 5 / 6;
  min-height: 0;
  border: 2px solid #efe7da;
  border-radius: 8px;
  background: var(--tile);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.orbit-card.face-down {
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.22) 0 18%, transparent 19%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent 42%),
    var(--wild);
  border-color: #efe7da;
}

.orbit-card.face-down .side {
  opacity: 0.72;
}

.orbit-card.face-down .symbol {
  background: rgba(255, 253, 248, 0.94);
  color: var(--wild);
  border-color: rgba(255, 255, 255, 0.7);
}

.side {
  position: absolute;
  inset: 0;
  background: var(--side-color);
}

.side.top {
  clip-path: polygon(0 0, 100% 0, 50% 50%);
}

.side.right {
  clip-path: polygon(100% 0, 100% 100%, 50% 50%);
}

.side.bottom {
  clip-path: polygon(100% 100%, 0 100%, 50% 50%);
}

.side.left {
  clip-path: polygon(0 100%, 0 0, 50% 50%);
}

.symbol {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  width: 42%;
  height: 62%;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(38, 53, 47, 0.22);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.96);
  color: var(--board);
  font-size: clamp(0.82rem, 2.5vw, 1.45rem);
  font-weight: 950;
  z-index: 2;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.16);
}

.preview-card .orbit-card {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.hand-card .orbit-card {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.message {
  width: min(720px, 100%);
  min-height: 48px;
  margin: 0;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  text-align: center;
  font-weight: 700;
}

.message.win {
  background: #26352f;
  border-color: #26352f;
  color: white;
}

.message.loss {
  background: #7b2e28;
  border-color: #7b2e28;
  color: white;
  box-shadow: 0 0 0 4px rgba(181, 70, 53, 0.18);
}

.move-log-panel {
  display: grid;
  gap: 12px;
  padding: 16px 20px;
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

.move-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.move-log-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.small-button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.move-log {
  display: grid;
  gap: 8px;
  max-height: 220px;
  margin: 0;
  padding: 0 0 0 24px;
  overflow: auto;
}

.move-log li {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.35;
}

.move-log li:last-child {
  border-color: var(--focus);
}

@keyframes hintPulse {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.08);
  }
}

@media (min-width: 901px) {
  .panel {
    max-height: 760px;
    overflow: auto;
  }

  .board-wrap {
    min-width: 0;
  }
}

@media (max-width: 900px) {
  .game-shell {
    width: min(100vw - 12px, 640px);
    padding: 6px 0 16px;
  }

  .site-nav {
    align-items: flex-start;
    flex-direction: column;
    width: min(100vw - 12px, 640px);
    padding-top: 9px;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .topbar,
  .scorebar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    display: flex;
    gap: 10px;
    padding: 14px;
  }

  .rules-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .rules-summary div {
    padding: 10px;
  }

  .rules-summary div:last-child {
    grid-column: 1 / -1;
  }

  .rules-summary span {
    font-size: 0.8rem;
  }

  .scorebar {
    padding: 14px;
  }

  .score-pair {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    flex-wrap: wrap;
    width: 100%;
  }

  .score-card {
    min-width: 0;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 4px;
    padding: 8px 6px;
  }

  .score-card span {
    width: 28px;
    height: 28px;
  }

  .score-card strong {
    font-size: 1.25rem;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "board"
      "panel";
    min-height: 0;
  }

  .panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-bottom: 0;
    padding: 12px;
    gap: 10px;
  }

  .current-card-panel {
    grid-column: 1;
    grid-row: span 2;
  }

  .action-group {
    grid-column: 2;
    align-content: start;
  }

  .status-card {
    padding: 10px;
  }

  .status-card strong {
    font-size: 1.25rem;
  }

  .action-button {
    justify-content: center;
    padding: 0 8px;
  }

  .action-icon {
    display: none;
  }

  .legend-card,
  .reset-button {
    grid-column: 1 / -1;
  }

  .control-card {
    min-width: 0;
  }

  .preview-card {
    width: min(110px, 100%);
  }

  .hand-card-panel {
    width: 100%;
    padding: 10px;
  }

  .hand-card {
    flex-basis: 74px;
    width: 74px;
  }

  .board-wrap {
    padding: 10px 8px 12px;
    gap: 10px;
  }

  .board {
    grid-template-columns: repeat(11, minmax(25px, 1fr));
    grid-template-rows: repeat(11, minmax(30px, 1.2fr));
    width: 100%;
    gap: 3px;
    padding: 8px;
  }

  .message {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 0.92rem;
  }

  .symbol {
    font-size: 0.78rem;
  }

  .move-log-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .brand-block h1 {
    font-size: 2.25rem;
  }

  .rules-summary {
    grid-template-columns: 1fr;
  }

  .rules-summary div:last-child {
    grid-column: auto;
  }

  .panel {
    grid-template-columns: 1fr;
  }

  .current-card-panel,
  .action-group {
    grid-column: auto;
  }

  .action-group {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board {
    grid-template-rows: repeat(11, minmax(27px, 1fr));
  }
}
