/* Rack Reader — pastel tiles on deep navy, mobile-first. */

:root {
  --bg: #252b3d;
  --bg-soft: #2e3550;
  --panel: #343c5a;
  --panel-2: #3d4668;
  --ink: #eef0f7;
  --muted: #a8aec7;
  --accent: #7c6ee6;
  --accent-2: #52b9a5;
  --ok: #52c07a;
  --bad: #e0606f;
  --gold: #f2c063;

  --tile-face: #f9f7f0;
  --crak: #c94f4f;
  --bam: #4d9e6e;
  --dot: #4a7db5;
  --wind: #7d6bb0;
  --flower: #d98caa;
  --joker: #c94f4f;

  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100%;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px calc(28px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0.3em 0; }
a { color: var(--accent-2); text-decoration: none; }
p { line-height: 1.45; }
.muted { color: var(--muted); }

/* ————— Buttons ————— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: transform 0.08s, filter 0.15s;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #9b6ee6); box-shadow: 0 4px 16px #0004; }
.btn.big { font-size: 19px; padding: 16px 22px; }
.btn.wide { display: flex; width: 100%; margin: 8px 0; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 8px 10px; font-size: 14px; }
.btn.danger { background: #7c3644; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-row { display: flex; gap: 8px; margin: 8px 0; }
.btn-row .btn { flex: 1; }

/* ————— Layout bits ————— */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.bar h1 { font-size: 20px; flex: 1; text-align: center; }
.spacer { width: 52px; }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 10px 0;
  box-shadow: 0 2px 10px #0003;
}

/* ————— Tiles ————— */
.tile {
  display: inline-flex;
  width: 44px;
  height: 60px;
  background: var(--tile-face);
  border-radius: 8px;
  box-shadow: 0 2px 4px #0006, inset 0 -3px 0 #d8d2c2;
  padding: 2px;
  margin: 2px;
  flex: none;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.2s;
}
.tile svg { width: 100%; height: 100%; }
.tile.mini { width: 32px; height: 44px; border-radius: 6px; margin: 1.5px; }
.tile.tappable { cursor: pointer; }
.tile.tappable:active { transform: translateY(-4px); }
.tile.selected {
  transform: translateY(-8px);
  box-shadow: 0 6px 14px #0008, 0 0 0 3px var(--accent-2);
}
.tile.locked { opacity: 0.55; filter: saturate(0.4); }
.tile.kept { box-shadow: 0 2px 4px #0006, 0 0 0 3px var(--ok); }
.tile.dim { opacity: 0.35; }
.tile.missing { opacity: 0.3; filter: grayscale(0.6); }
.tile.joker-used { box-shadow: 0 2px 4px #0006, 0 0 0 3px var(--gold); }
.tile.mark {
  box-shadow: 0 2px 4px #0006, 0 0 0 3px var(--accent-2);
  transform: translateY(-6px);
}

.rack {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  padding: 10px 4px;
  background: var(--bg-soft);
  border-radius: var(--radius);
  margin: 10px 0;
}

/* ————— Hand rows (card-print style) ————— */
.hand-row {
  background: var(--tile-face);
  color: #333;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0;
  position: relative;
}
.hand-row.tappable { cursor: pointer; transition: transform 0.08s, box-shadow 0.15s; }
.hand-row.tappable:active { transform: scale(0.98); }
.hand-row.right { box-shadow: 0 0 0 3px var(--ok); }
.hand-row.faded { opacity: 0.65; }
.hand-row.broken { color: #a33; font-size: 14px; }
.hand-groups {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
}
.hand-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 12.5px; color: #777; }
.hand-name { font-weight: 600; color: #555; }
.hand-sub { font-weight: 700; color: var(--accent); }
.g-blue { color: #3667a6; }
.g-red { color: #c04343; }
.g-green { color: #3d8a5f; }
.g-wind { color: #6b5a99; }
.g-f { color: #8a7f5c; }

/* ————— Home ————— */
.home .logo { text-align: center; margin: 18px 0 6px; }
.logo-tiles { display: flex; justify-content: center; }
.logo-tiles .tile { transform: rotate(-4deg); }
.logo-tiles .tile:nth-child(2) { transform: rotate(3deg); }
.logo-tiles .tile:nth-child(3) { transform: rotate(-2deg); }
.logo-tiles .tile:nth-child(4) { transform: rotate(5deg); }
.title { font-size: 34px; letter-spacing: 0.5px; margin: 8px 0 0; }
.subtitle { color: var(--muted); margin: 2px 0 14px; }
.daily-head { display: flex; justify-content: space-between; align-items: center; font-size: 17px; }
.daily-title { font-weight: 700; }
.flame { font-weight: 700; color: var(--gold); }
.daily-done { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; color: var(--ok); }
.rank-line { display: flex; justify-content: space-between; margin-bottom: 6px; }
.rank-next { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.weak-card { font-size: 14.5px; }
.home-links { display: flex; justify-content: space-around; margin: 16px 0; font-size: 15px; }
.card-note { color: var(--gold); font-size: 13.5px; text-align: center; }

.meter { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; flex: 1; }
.meter-fill { height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 5px; transition: width 0.4s; }

/* ————— Level map ————— */
.level-list { display: flex; flex-direction: column; gap: 8px; }
.level-node {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.level-node.tappable { cursor: pointer; }
.level-node.tappable:active { transform: scale(0.985); }
.level-node.locked { opacity: 0.55; }
.level-num {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9b6ee6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
  flex: none;
}
.level-node.locked .level-num { background: var(--panel-2); }
.level-info { flex: 1; display: flex; flex-direction: column; }
.tagline { color: var(--muted); font-size: 13px; }
.level-stars { color: var(--gold); font-size: 15px; letter-spacing: 1px; }

/* ————— Play ————— */
.progress { display: flex; gap: 4px; flex: 1; justify-content: center; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--panel-2); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.now { box-shadow: 0 0 0 2px var(--accent); }
.combo { color: var(--gold); font-weight: 800; min-width: 52px; text-align: right; }

.prompt { font-size: 16.5px; font-weight: 600; text-align: center; margin: 8px 4px; }
.timerbar { height: 8px; background: var(--bg-soft); border-radius: 4px; overflow: hidden; margin: 4px 0; }
.timerfill { height: 100%; background: var(--accent-2); width: 100%; transition: width 0.2s linear; }
.timerfill.low { background: var(--bad); }

.answers { margin-top: 10px; }
.answers.chips, .answers.yesno { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.answers.chips .btn.choice { flex: 1 1 40%; }
.answers.yesno .btn.choice { flex: 1; padding: 18px; font-size: 18px; }
.answers.numpad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.answers.numpad .btn.num { padding: 16px 0; font-size: 20px; }
.answers.hands .hand-row { border: 2px solid transparent; }
.answers.cardscan { max-height: 46vh; overflow-y: auto; background: var(--bg-soft); border-radius: var(--radius); padding: 8px 10px; }
.cat-head { color: var(--accent-2); font-size: 14px; text-transform: uppercase; letter-spacing: 1px; margin: 10px 0 2px; }
.shown-hands { margin: 4px 0; }

.toast {
  position: fixed;
  left: 50%; top: 38%;
  transform: translate(-50%, -50%) scale(1);
  background: var(--ok);
  color: #fff;
  padding: 16px 26px;
  border-radius: 18px;
  font-size: 20px;
  box-shadow: 0 10px 30px #0008;
  animation: pop 0.25s ease-out;
  z-index: 10;
  text-align: center;
  pointer-events: none;
}
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.feedback { animation: fadein 0.25s; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }
.wrong-head { color: var(--bad); text-align: center; }
.your-rack-label { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.reveal-hands { margin: 8px 0; }
.best-box { border: 2px solid var(--accent-2); }
.best-label { font-weight: 700; margin: 2px 0 6px; }
.explain-groups { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.explain-group { display: flex; background: var(--bg-soft); border-radius: 8px; padding: 3px; }
.explain-key { font-size: 12.5px; color: var(--muted); }

.interstitial { text-align: center; padding-top: 8vh; }
.interstitial .card { text-align: left; }

/* ————— Results ————— */
.results { text-align: center; padding-top: 5vh; }
.stars-big { font-size: 52px; color: var(--gold); letter-spacing: 6px; animation: pop2 0.5s ease-out; }
@keyframes pop2 { 0% { transform: scale(0.3); opacity: 0; } 60% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }
.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.result-grid .stat { background: var(--panel); border-radius: 10px; padding: 10px 4px; display: flex; flex-direction: column; }
.result-grid b { font-size: 18px; }
.result-grid span { font-size: 11.5px; color: var(--muted); }
.result-dots { display: flex; justify-content: center; gap: 5px; margin: 6px 0 14px; flex-wrap: wrap; }
.unlock-note { color: var(--gold); font-weight: 700; animation: pop 0.4s; }
.result-actions { margin-top: 10px; }

/* ————— Stats ————— */
.cat-stat { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.cat-name { width: 120px; font-size: 14px; flex: none; }
.cat-pct { width: 80px; text-align: right; font-size: 13px; color: var(--muted); flex: none; }

/* ————— Cards & editor ————— */
.source-row { display: flex; gap: 10px; align-items: baseline; margin: 8px 0; cursor: pointer; }
.import-box, .import-url, .text-input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--panel-2);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  margin: 6px 0;
  font-family: inherit;
}
.text-input.notation { font-family: ui-monospace, Menlo, monospace; font-size: 17px; }
.import-status { min-height: 20px; font-size: 14px; margin: 4px 0; }
.import-status.ok { color: var(--ok); }
.import-status.err { color: var(--bad); }
.file-btn { cursor: pointer; }
.card-browser { max-height: 60vh; overflow-y: auto; }

.editor-list .hand-row { display: block; }
.hand-row .del { position: absolute; top: 6px; right: 6px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-top: 10px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.keypad { margin: 8px 0; }
.key-row { display: flex; gap: 5px; margin: 5px 0; }
.btn.key { flex: 1; padding: 10px 0; font-size: 15px; background: var(--panel-2); }
.btn.key.wide2 { flex: 2; }
.btn.key.suit-a { color: #8fb7dd; }
.btn.key.suit-b { color: #e8909c; }
.btn.key.suit-c { color: #a3c780; }
.preview-box { margin: 10px 0; }
.preview-ok { color: var(--ok); font-size: 14px; }
.preview-err { color: var(--bad); font-size: 14px; }
.hint { font-size: 13px; }

/* ————— Charts —————
   Series hues and the heatmap ramp were validated with the data-viz palette
   checker against both surfaces below (card and plot well): lightness band,
   chroma floor, CVD separation, normal-vision floor, and 3:1 contrast all pass.
   Charts are single-series, so identity never rests on colour alone, and each
   one ships a table-view twin. */
:root {
  --viz-well: #252b3d;          /* plot surface (darker well inside a card) */
  --viz-acc: #07ac86;           /* accuracy series */
  --viz-speed: #be8805;         /* speed series */
  --viz-grid: #3f4970;          /* hairline grid, one shade off the surface */
  --viz-axis-ink: #9aa1bd;
  --heat-0: #2b3149;
  --heat-1: #6a5fb5;
  --heat-2: #8a7ceb;
  --heat-3: #a99ff5;
  --heat-4: #cec7fb;
}

.viz { margin: 2px 0 6px; }
.viz-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.viz-head h4 { margin: 0; font-size: 15px; }
.viz-now { font-size: 17px; font-weight: 700; }
.viz-plot { position: relative; background: var(--viz-well); border-radius: 10px; padding: 8px 8px 4px; }
.viz-svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-cross { stroke: var(--viz-axis-ink); stroke-width: 1; }
.viz-axis { fill: var(--viz-axis-ink); font-size: 9px; font-variant-numeric: tabular-nums; }
.viz-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viz-area { stroke: none; opacity: 0.16; }
.viz-line.viz-acc { stroke: var(--viz-acc); }
.viz-area.viz-acc, .viz-dot.viz-acc { fill: var(--viz-acc); }
.viz-line.viz-speed { stroke: var(--viz-speed); }
.viz-area.viz-speed, .viz-dot.viz-speed { fill: var(--viz-speed); }
.viz-dot { stroke: var(--viz-well); stroke-width: 2; } /* 2px surface ring, not a border */
.viz-tip {
  position: absolute; top: 2px; transform: translateX(-50%);
  background: var(--panel-2); color: var(--ink);
  font-size: 12px; padding: 4px 8px; border-radius: 7px;
  white-space: nowrap; pointer-events: none; z-index: 2;
  box-shadow: 0 2px 8px #0006;
}
.viz-empty, .viz-note { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }

/* Activity heatmap */
.heat-plot { padding: 10px; }
.heat-grid { display: flex; gap: 3px; justify-content: space-between; }
.heat-col { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.heat-cell {
  aspect-ratio: 1; border-radius: 3px; background: var(--heat-0);
  min-height: 9px; cursor: default;
}
.heat-cell.heat-1 { background: var(--heat-1); }
.heat-cell.heat-2 { background: var(--heat-2); }
.heat-cell.heat-3 { background: var(--heat-3); }
.heat-cell.heat-4 { background: var(--heat-4); }
.heat-cell.heat-future { background: transparent; }
.heat-cell:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.heat-legend .heat-cell { width: 11px; height: 11px; min-height: 0; aspect-ratio: auto; }

/* Bar rows — nominal categories all share one hue (length carries the value) */
.bar-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.bar-label { width: 108px; flex: none; font-size: 13px; }
.bar-track { flex: 1; height: 9px; background: var(--viz-well); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--viz-acc); border-radius: 5px; }
.bar-value { width: 74px; flex: none; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Stat tiles */
.tile-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 4px; }
.tile-stat { background: var(--viz-well); border-radius: 10px; padding: 9px 4px; display: flex; flex-direction: column; align-items: center; }
.tile-stat b { font-size: 18px; }
.tile-stat span { font-size: 10.5px; color: var(--muted); text-align: center; }
.tile-delta { font-size: 11px; font-weight: 700; margin-top: 2px; }
.tile-delta.up { color: var(--ok); }
.tile-delta.down { color: var(--bad); }

/* Table-view twin */
.viz-twin { margin-top: 6px; }
.viz-toggle { padding: 4px 0; }
.viz-table-wrap { max-height: 220px; overflow: auto; margin-top: 4px; }
.viz-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.viz-table caption { text-align: left; color: var(--muted); font-size: 12px; padding-bottom: 4px; }
.viz-table th, .viz-table td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--viz-grid); font-variant-numeric: tabular-nums; }
.viz-table th { color: var(--muted); font-weight: 600; }

/* Badges */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 8px; }
.badge { background: var(--viz-well); border-radius: 10px; padding: 9px 6px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.badge.locked { opacity: 0.45; }
.badge.got { box-shadow: inset 0 0 0 1.5px var(--gold); }
.badge-icon { font-size: 22px; }
.badge-name { font-size: 12px; font-weight: 700; }
.badge-desc { font-size: 10.5px; color: var(--muted); line-height: 1.25; }
.badge-unlocks { margin: 10px 0; }
.badge-pop {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--panel); border-radius: 12px; padding: 10px 12px; margin: 6px 0;
  box-shadow: inset 0 0 0 1.5px var(--gold); animation: pop 0.35s ease-out;
}
.badge-pop .badge-icon { font-size: 26px; }
.badge-pop span { font-size: 13px; }

/* ————— Small screens ————— */
@media (max-width: 420px) {
  .tile { width: 40px; height: 55px; }
  .hand-groups { font-size: 17px; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .tile-row { grid-template-columns: repeat(2, 1fr); }
  .bar-label { width: 88px; font-size: 12px; }
  .bar-value { width: 66px; }
}

/* ————— Account & sync ————— */
.account-body { margin-bottom: 8px; }
.sync-status { min-height: 22px; font-size: 14.5px; margin: 4px 2px; }
.sync-status.ok { color: var(--ok); }
.sync-status.err { color: var(--bad); }
.pair-code { margin-top: 10px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 26px;
  letter-spacing: 3px;
  font-weight: 700;
  color: var(--accent-2);
  background: var(--bg-soft);
  padding: 8px 14px;
  border-radius: 10px;
  user-select: all;
}
