:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6b66;
  --line: #e3e1da;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --danger: #b23a2f;
  --bam: #1f7a3a;
  --crak: #b3261e;
  --dot: #1e4f9c;
  --tile-bg: #fffdf5;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
nav { display: flex; gap: 4px; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; font-size: 15px; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--bg); color: var(--ink); font-weight: 600; }
main { max-width: 900px; margin: 0 auto; padding: 12px; }
.view { display: none; }
.view.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
h2 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.status { font-size: 14px; padding: 8px 10px; border-radius: 8px; background: #f1efe6; margin: 8px 0 0; }
.status.error { background: #fbe9e6; color: var(--danger); }
.status.ok { background: #e6f4ee; color: var(--accent); }

/* tiles */
.tile {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  width: 40px; height: 54px; border-radius: 6px; background: var(--tile-bg);
  border: 1px solid #d9d4c2; box-shadow: 0 1px 0 #cfc9b3, 0 2px 3px rgba(0,0,0,.08);
  font-weight: 700; font-size: 20px; line-height: 1; user-select: none; cursor: pointer; position: relative;
}
.tile i { font-style: normal; font-size: 9px; font-weight: 600; letter-spacing: .3px; margin-top: 3px; text-transform: uppercase; }
.tile.s-B { color: var(--bam); }
.tile.s-C { color: var(--crak); }
.tile.s-D { color: var(--dot); }
.tile.wind { color: #222; }
.tile.dragon-DG { color: var(--bam); }
.tile.dragon-DR { color: var(--crak); }
.tile.dragon-DW { color: var(--dot); }
.tile.flower { color: #8a4b9b; }
.tile.joker { color: #a86400; background: #fff7e0; }
.tile.mini { width: 26px; height: 34px; font-size: 13px; vertical-align: middle; cursor: default; }
.tile.mini i { font-size: 6px; margin-top: 1px; }
.tile.ghost { opacity: .35; border-style: dashed; }
.tile.need { outline: 2px solid var(--accent); outline-offset: -2px; }
.tile.joker-fill { background: #fff7e0; }
.tile.disabled { opacity: .3; cursor: default; }
.tile .cnt { position: absolute; top: -6px; right: -6px; background: var(--ink); color: #fff; font-size: 10px; border-radius: 10px; min-width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

.rack { display: flex; flex-wrap: wrap; gap: 6px; min-height: 60px; padding: 6px; background: #efece2; border-radius: 8px; }
.picker { display: flex; flex-direction: column; gap: 8px; }
.picker .row { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.picker .row .lbl { width: 46px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; }

/* results */
.results { display: flex; flex-direction: column; gap: 8px; }
.hand { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.hand.complete { border-color: var(--accent); background: #eef7f2; }
.hand-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.hand-title { font-weight: 600; font-size: 14px; }
.hand-title .sec { color: var(--muted); font-weight: 500; }
.hand-need { font-size: 13px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.hand-need.n0 { color: #fff; background: var(--accent); padding: 2px 8px; border-radius: 12px; }
.hand-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.hand-tiles { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; align-items: flex-end; }
.hand-tiles .grp { display: flex; gap: 2px; margin-right: 6px; }
.hand-foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
.hand-foot b { color: var(--ink); font-weight: 600; }
.more { text-align: center; }

/* card editor */
textarea { width: 100%; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; border: 1px solid var(--line); border-radius: 8px; padding: 10px; resize: vertical; margin: 8px 0; }
.errors { color: var(--danger); font-size: 13px; white-space: pre-wrap; margin-bottom: 8px; }
.fmt { margin-top: 12px; font-size: 13px; }
.fmt pre { background: #f1efe6; padding: 10px; border-radius: 8px; overflow: auto; }
.prose p { margin: 8px 0; }

@media (max-width: 480px) {
  .tile { width: 34px; height: 46px; font-size: 17px; }
  .tile i { font-size: 8px; }
  .picker .row .lbl { width: 100%; }
}
