:root {
  color-scheme: light;
  --ink: #202325;
  --muted: #687077;
  --line: #d7ddd8;
  --surface: #fbfcf8;
  --surface-2: #eef4ee;
  --panel: #ffffff;
  --green: #39a86b;
  --red: #d94a45;
  --blue: #4778d7;
  --yellow: #e4b43f;
  --violet: #7655d6;
  --shadow: 0 18px 55px rgba(31, 42, 38, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(57, 168, 107, 0.16), transparent 38%),
    linear-gradient(315deg, rgba(71, 120, 215, 0.16), transparent 34%),
    #f7f8f3;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 620px);
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  align-items: stretch;
  padding: 0;
}

.game-surface {
  width: 100%;
  min-height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
}

.topbar {
  min-height: 58px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: clamp(18px, 4vw, 24px);
  min-width: 0;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background:
    linear-gradient(90deg, transparent 47%, rgba(255, 255, 255, 0.65) 48% 52%, transparent 53%),
    linear-gradient(180deg, var(--red) 0 50%, var(--green) 50% 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  flex: 0 0 auto;
}

.match-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.match-strip span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 22px;
  text-decoration: none;
}

.icon-button:hover {
  border-color: #aeb8af;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-panel {
  margin: 12px 14px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 8px;
  background: var(--panel);
}

.status-panel strong {
  display: block;
  font-size: 16px;
  line-height: 1.25;
}

.status-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.status-panel.warning {
  border-left-color: var(--yellow);
}

.status-panel.danger {
  border-left-color: var(--red);
}

.status-panel.over {
  border-left-color: var(--violet);
}

.status-panel.hint {
  border-left-color: var(--blue);
}

.board {
  padding: 12px 14px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.player-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.player-row.active {
  border-color: #2c8e5c;
  box-shadow: 0 0 0 3px rgba(57, 168, 107, 0.14);
}

.player-header {
  min-height: 46px;
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  background: var(--surface-2);
}

.player-name {
  min-width: 0;
}

.player-name strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-name span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.player-badges {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.badge small {
  color: var(--muted);
  font-weight: 600;
}

.player-body {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.code-row,
.card-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.code-cell {
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: 14px;
}

.code-cell.hidden {
  color: #6b736e;
  background:
    linear-gradient(135deg, #fff 25%, #f1f4f0 25% 50%, #fff 50% 75%, #f1f4f0 75%);
  background-size: 10px 10px;
}

.card {
  position: relative;
  min-width: 0;
  height: clamp(56px, 13vw, 76px);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  cursor: default;
  display: grid;
  place-items: center;
  overflow: hidden;
  user-select: none;
}

.card.selectable {
  cursor: pointer;
}

.card:disabled {
  color: inherit;
  opacity: 1;
}

.card.selectable:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(32, 35, 37, 0.14);
}

.card.selected {
  outline: 3px solid #1d1f20;
  outline-offset: 2px;
}

.card:focus-visible,
.icon-button:focus-visible,
.primary-action:focus-visible,
.secondary-action:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.card.blocked::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 6px;
  background: #101315;
  z-index: 2;
}

.card.blocked::after {
  content: "⌕";
  position: absolute;
  right: 6px;
  top: 7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.85);
  color: #101315;
  font-size: 11px;
  font-weight: 900;
  z-index: 3;
}

.card-face {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 8px;
  text-align: center;
}

.own-card {
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.86) 0 11%, transparent 12%),
    repeating-linear-gradient(45deg, #e9ede8 0 8px, #f8faf5 8px 16px);
}

.own-card .number {
  color: var(--ink);
  font-size: clamp(24px, 8vw, 42px);
  line-height: 1;
  font-weight: 900;
}

.own-card .meta {
  position: absolute;
  bottom: 5px;
  left: 6px;
  right: 6px;
  color: #747c76;
  font-size: 10px;
  font-weight: 700;
}

.opponent-card {
  color: #fff;
}

.opponent-card.red {
  background: var(--red);
}

.opponent-card.green {
  background: #2c8a57;
}

.opponent-card.blue {
  background: #3a63c0;
}

.opponent-card.yellow {
  background: var(--yellow);
  color: #30230a;
}

.opponent-card .color-symbol {
  font-size: clamp(22px, 7vw, 36px);
  line-height: 1;
  font-weight: 900;
}

.opponent-card .meta {
  position: absolute;
  bottom: 5px;
  left: 6px;
  right: 6px;
  color: currentColor;
  font-size: 11px;
  font-weight: 800;
}

.control-dock {
  padding: 10px 14px 12px;
  display: grid;
  grid-template-columns: 98px 112px 1fr;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(18px);
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.primary-action,
.secondary-action {
  min-height: 52px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 900;
  cursor: pointer;
}

.primary-action {
  background: #1e6f49;
  color: #fff;
}

.primary-action:disabled {
  cursor: not-allowed;
  background: #cdd5ce;
  color: #6f786f;
}

.secondary-action {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.event-log {
  padding: 0 14px 18px;
}

.event-log h2 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.event-log ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.event-log li {
  min-height: 32px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  color: #4d5550;
  font-size: 12px;
  line-height: 1.35;
}

.help-page {
  display: block;
}

.help-intro,
.help-section {
  padding: 18px 18px 0;
}

.help-intro {
  padding-top: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.help-intro h1 {
  margin: 0;
  max-width: 11ch;
  font-size: clamp(34px, 9vw, 58px);
  line-height: 0.98;
  letter-spacing: 0;
}

.help-intro p,
.help-section p {
  color: var(--muted);
  line-height: 1.45;
}

.help-section h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.rule-grid {
  display: grid;
  gap: 10px;
}

.rule-item,
.score-table,
.tip-strip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rule-item {
  padding: 12px;
}

.rule-item strong {
  display: block;
  margin-bottom: 4px;
}

.rule-item p {
  margin: 0;
}

.step-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  counter-reset: steps;
}

.step-list li {
  min-height: 42px;
  padding: 10px 12px 10px 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  position: relative;
  line-height: 1.35;
  counter-increment: steps;
}

.step-list li::before {
  content: counter(steps);
  position: absolute;
  left: 12px;
  top: 9px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.score-table {
  overflow: hidden;
}

.score-table div {
  min-height: 40px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

.score-table div:last-child {
  border-bottom: 0;
}

.score-table strong {
  font-size: 16px;
}

.tip-strip {
  padding: 4px 12px;
}

.tip-strip p {
  margin: 10px 0;
}

.play-link {
  min-height: 52px;
  margin: 14px 0 22px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #1e6f49;
  color: #fff;
  text-decoration: none;
  font-weight: 900;
}

@media (max-width: 520px) {
  .app-shell,
  .game-surface {
    min-height: 100svh;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    min-height: 82px;
    padding: 8px 10px 6px;
    row-gap: 4px;
  }

  .match-strip {
    grid-column: 1 / -1;
    order: 3;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .status-panel,
  .board,
  .control-dock,
  .event-log {
    margin-left: 0;
    margin-right: 0;
  }

  .status-panel {
    margin-top: 8px;
    border-left-width: 4px;
    border-radius: 0;
    border-right: 0;
    border-left-style: solid;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .status-panel p {
    font-size: 12px;
  }

  .board {
    padding: 8px;
    gap: 8px;
  }

  .player-header {
    min-height: 40px;
  }

  .player-header,
  .player-body {
    padding-left: 8px;
    padding-right: 8px;
  }

  .player-body {
    padding-top: 6px;
    padding-bottom: 6px;
    gap: 5px;
  }

  .badge {
    min-height: 24px;
    padding-left: 6px;
    padding-right: 6px;
    font-size: 11px;
  }

  .code-cell {
    height: 22px;
  }

  .card {
    height: 46px;
  }

  .own-card .meta,
  .opponent-card .meta {
    display: none;
  }

  .card-row,
  .code-row {
    gap: 5px;
  }

  .control-dock {
    grid-template-columns: 78px 78px 1fr;
    padding-left: 8px;
    padding-right: 8px;
    position: static;
  }

  .help-intro,
  .help-section {
    padding-left: 14px;
    padding-right: 14px;
  }
}

@media (max-width: 520px) and (max-height: 720px) {
  .topbar {
    min-height: 56px;
    grid-template-columns: 1fr auto auto;
    padding: 6px 8px;
  }

  .brand {
    font-size: 18px;
  }

  .brand-mark {
    width: 20px;
    height: 20px;
  }

  .match-strip {
    grid-column: auto;
    order: 0;
    padding-bottom: 0;
  }

  .match-strip span:first-child {
    display: none;
  }

  .top-actions {
    gap: 6px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .status-panel {
    margin-top: 6px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .status-panel strong {
    font-size: 15px;
  }

  .status-panel p {
    font-size: 12px;
    line-height: 1.25;
  }

  .board {
    padding-top: 6px;
    padding-bottom: 6px;
    gap: 5px;
  }

  .player-header {
    min-height: 34px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .player-name strong {
    font-size: 14px;
  }

  .player-name span {
    display: none;
  }

  .badge {
    min-height: 20px;
    padding-left: 5px;
    padding-right: 5px;
    font-size: 10px;
  }

  .player-body {
    padding-top: 4px;
    padding-bottom: 4px;
    gap: 4px;
  }

  .code-cell {
    height: 16px;
    font-size: 11px;
  }

  .card {
    height: 44px;
  }

  .own-card .number {
    font-size: 26px;
  }

  .opponent-card .color-symbol {
    font-size: 26px;
  }

  .control-dock {
    padding-top: 7px;
    padding-bottom: 8px;
  }

  .primary-action,
  .secondary-action {
    min-height: 44px;
  }
}
