:root {
  --green: #6aaa64;
  --yellow: #c9b458;
  --gray: #787c7e;
  --key: #d3d6da;
  --border: #d3d6da;
  --border-filled: #878a8c;
  --text: #1a1a1b;
  --muted: #5c5f61;
  --red: #c8102e;
  --felt: #1f6b3a;
  --hot: #d9534f;
  --warm: #e6a23c;
  --cold: #5b9bd5;
  --tile: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: #fff;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 12px 24px;
}

/* ------------------------------------------------------------ header */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  margin-bottom: 10px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand h1 {
  font-size: 30px;
  letter-spacing: 0.08em;
  margin: 0;
  font-weight: 800;
  color: #4269e0;
}

.brand .sub {
  font-size: 12px;
  color: var(--muted);
}

.brand .sub a {
  color: #1a73e8;
  font-weight: 600;
  text-decoration: none;
}

.icons button {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 3px;
  color: var(--text);
}

.icons button:hover {
  color: var(--green);
}

/* ------------------------------------------------------------- debug */

.debug-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: #fff7d6;
  border: 1px dashed #d4a017;
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 10px;
  font-size: 13px;
}

.debug-tag {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9a7200;
  font-size: 11px;
}

.debug-bar input {
  font: inherit;
  padding: 3px 6px;
  border: 1px solid var(--border-filled);
  border-radius: 4px;
  width: 110px;
}

.debug-bar button {
  font: inherit;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border-filled);
  background: #fff;
  cursor: pointer;
}

/* ---------------------------------------------------------- scenario */

.scenario {
  background: radial-gradient(ellipse at center, #2b7d47 0%, var(--felt) 70%, #164d2a 100%);
  border-radius: 14px;
  padding: 12px 14px 10px;
  color: #fff;
  box-shadow: inset 0 0 0 4px #5a3b1c, 0 2px 6px rgba(0, 0, 0, 0.25);
  margin-bottom: 12px;
}

.scenario-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  margin-bottom: 8px;
}

.scenario-label {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.scenario-share {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 8px;
  cursor: pointer;
}

.seats {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 6px;
  padding-bottom: 8px;
}

.seat {
  text-align: center;
}

.seat:not(.board) {
  transform: translateY(8px);
}

.seat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.8;
  margin-bottom: 4px;
}

.cards {
  display: flex;
  justify-content: center;
  gap: 2px;
}

.card-img {
  width: 48px;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  background: #fff;
}

.card-slot {
  width: 48px;
  height: 67px;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: 4px;
}

.card-back {
  width: 48px;
  height: 67px;
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, #7a1f2b 0 4px, #5e1420 4px 8px);
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  color: rgba(255, 255, 255, 0.85);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.stat {
  text-align: center;
  margin-top: 10px;
  font-size: 14px;
}

.stat strong {
  font-size: 22px;
  font-weight: 800;
  margin-left: 6px;
}

.stat small {
  display: block;
  opacity: 0.8;
  font-size: 12px;
  margin-top: 2px;
}

/* -------------------------------------------------------------- grid */

.grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  margin: 8px 0 14px;
}

.row {
  display: grid;
  grid-template-columns: var(--tile) var(--tile) 92px;
  gap: 6px;
  align-items: center;
}

.tile {
  width: var(--tile);
  height: var(--tile);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  user-select: none;
  position: relative;
  background: #fff;
}

.tile.filled {
  border-color: var(--border-filled);
  animation: pop 0.1s ease-in-out;
}

.tile .rank {
  font-size: 26px;
  line-height: 1;
}

.tile .suit {
  font-size: 18px;
  line-height: 1;
  margin-top: 3px;
}

.suit-s,
.suit-c {
  color: #1a1a1b;
}

.suit-h,
.suit-d {
  color: var(--red);
}

.suit-empty {
  color: #b7babd;
}

.tile.graded {
  color: #fff;
  border-color: transparent;
  animation: flip 0.45s ease-in-out;
}

.tile.graded .suit {
  color: #fff;
}

.g-correct {
  background: var(--green);
}

.g-present {
  background: var(--yellow);
}

.g-absent {
  background: var(--gray);
}

.tile .suit.chip {
  padding: 1px 7px;
  border-radius: 10px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  font-size: 15px;
  margin-top: 4px;
}

.chip-present {
  background: var(--green);
}

.chip-absent {
  background: #4a4d4f;
}

.hint {
  height: var(--tile);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
}

.hint-eq {
  font-weight: 700;
  color: var(--text);
}

.hint-arrow {
  font-size: 18px;
  line-height: 1;
  margin-top: 2px;
  font-weight: 800;
}

.hint-hot {
  border-style: solid;
  border-color: var(--hot);
}

.hint-hot .hint-arrow {
  color: var(--hot);
}

.hint-warm {
  border-style: solid;
  border-color: var(--warm);
}

.hint-warm .hint-arrow {
  color: var(--warm);
}

.hint-cold {
  border-style: solid;
  border-color: var(--cold);
}

.hint-cold .hint-arrow {
  color: var(--cold);
}

.row.shake {
  animation: shake 0.5s;
}

.row.is-hint {
  grid-template-columns: minmax(0, calc(var(--tile) * 2 + 92px + 12px));
}

.hint-note {
  height: var(--tile);
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 2px solid var(--border-filled);
  border-radius: 6px;
  font-weight: 700;
  font-size: 14px;
  background: #f4f4f5;
}

/* ---------------------------------------------------------- keyboard */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.keyboard.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.keyrow {
  display: flex;
  gap: 5px;
  justify-content: center;
  width: 100%;
}

.key {
  background: var(--key);
  border: none;
  border-radius: 4px;
  height: 52px;
  min-width: 32px;
  flex: 1;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.1s;
}

.key:hover {
  filter: brightness(0.95);
}

.key.selected {
  outline: 3px solid var(--text);
  outline-offset: -3px;
}

.key-suit {
  font-size: 26px;
  max-width: 64px;
}

.key-wide {
  flex: 1.4;
  font-size: 13px;
  max-width: 80px;
}

.key.k-present {
  background: var(--green);
  color: #fff;
}

.key.k-present.key-suit {
  color: #fff;
}

.key.k-absent {
  background: var(--gray);
  color: #fff;
}

.key.k-absent.key-suit {
  color: #fff;
}

/* ----------------------------------------------------------- outcome */

.outcome {
  text-align: center;
  margin: 10px 0 14px;
  padding: 12px;
  border-radius: 10px;
  background: #f4f4f5;
}

.outcome h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.outcome p {
  margin: 0 0 10px;
  color: var(--muted);
}

.btn {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.btn.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-filled);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.practice-tools {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 10px;
}

.practice-tools .btn {
  padding: 6px 12px;
  font-size: 14px;
}

.hint-choices {
  display: flex;
  gap: 8px;
}

.outcome .explain {
  text-align: left;
  margin: 8px 0 12px;
}

.outcome .explain p {
  color: var(--text);
  text-align: left;
  margin: 4px 0;
  font-size: 13px;
}

.streak-line {
  font-weight: 700;
}

.filter-group {
  margin: 10px 0;
}

.filter-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.filter-note,
.practice-streak,
.split-note {
  font-size: 13px;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  border: 1px solid var(--border-filled);
  background: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}

.filter-chip.selected {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.practice-hand {
  font-weight: 700;
  margin-bottom: 0;
}

.text-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--green);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}

.practice-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.tab {
  flex: 1;
  border: 1px solid var(--border-filled);
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.tab.selected {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.modal-card h3 {
  margin: 12px 0 4px;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.split-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  padding: 2px 0;
}

.split-note {
  margin-top: 10px;
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------- toast */

.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 50;
}

.toast.show {
  opacity: 1;
}

/* ------------------------------------------------------------ modals */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 12px;
}

.modal-card {
  background: #fff;
  border-radius: 10px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  padding: 18px 20px 20px;
  position: relative;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.modal-card h2 {
  margin: 0 0 10px;
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.modal-card p,
.modal-card li {
  font-size: 14px;
  line-height: 1.45;
}

.modal-card ul {
  padding-left: 18px;
}

.close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
}

.example {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 8px 0 4px;
}

.example .tile {
  --tile: 46px;
}

.example .tile .rank {
  font-size: 20px;
}

.example .tile .suit {
  font-size: 14px;
}

.example .tile .suit.chip {
  font-size: 12px;
  padding: 0 6px;
}

.example .hint {
  --tile: 46px;
  width: 74px;
  font-size: 12px;
}

.stats-row {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin: 8px 0 14px;
}

.stats-row div b {
  display: block;
  font-size: 28px;
  font-weight: 800;
}

.stats-row div span {
  font-size: 11px;
  color: var(--muted);
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
}

.dist-label {
  width: 12px;
  font-size: 13px;
  font-weight: 700;
}

.dist-bar {
  background: var(--gray);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  text-align: right;
  padding: 2px 6px;
  border-radius: 2px;
}

.dist-bar.current {
  background: var(--green);
}

.stats-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}

.stats-footer .next b {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

.stats-footer .next span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}

.stats-result {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 16px;
}

/* -------------------------------------------------------- animations */

@keyframes pop {
  0% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes flip {
  0% {
    transform: rotateX(0);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

@keyframes shake {
  10%,
  90% {
    transform: translateX(-1px);
  }
  20%,
  80% {
    transform: translateX(2px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-4px);
  }
  40%,
  60% {
    transform: translateX(4px);
  }
}

@media (max-width: 400px) {
  :root {
    --tile: 56px;
  }

  .row {
    grid-template-columns: var(--tile) var(--tile) 80px;
  }

  .row.is-hint {
    grid-template-columns: minmax(0, calc(var(--tile) * 2 + 80px + 12px));
  }

  .hint-note {
    font-size: 13px;
  }

  .card-img,
  .board .card-img,
  .card-back,
  .card-slot {
    width: 32px;
  }

  .card-back,
  .card-slot {
    height: 44px;
  }

  .key {
    min-width: 0;
    height: 46px;
    font-size: 13px;
    padding: 0;
  }

  .keyrow {
    gap: 3px;
  }

  .brand h1 {
    font-size: 24px;
  }

  .scenario-label {
    flex-basis: 100%;
  }

  .seat:not(.board) {
    transform: translateY(4px);
  }

  .seats {
    padding-bottom: 4px;
  }
}
