:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --ink: #1d2420;
  --muted: #5b655f;
  --line: #d6d9d2;
  --brand: #2f5d46;
  --brand-ink: #ffffff;
  --herb: #e5f1e3;
  --herb-line: #4f8a55;
  --woody: #f3e9dc;
  --woody-line: #8a5f36;
  --suspect: #f2b632;
  --cross: #b3261e;
  --focus: #1a5fd0;
  --radius: 10px;
  --tap: 48px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100dvh; padding-bottom: calc(var(--tabs-h) + var(--safe-b)); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.noscript { padding: 1rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(.4rem + env(safe-area-inset-top, 0px)) max(.75rem, env(safe-area-inset-right)) .4rem max(.75rem, env(safe-area-inset-left));
  background: var(--brand); color: var(--brand-ink);
}
.title { font-size: 1rem; font-weight: 700; white-space: nowrap; }
.title span { font-weight: 400; opacity: .85; }
.save-status { font-size: .75rem; opacity: .9; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-status.bad { background: #fff; color: var(--cross); padding: .15rem .4rem; border-radius: 6px; font-weight: 600; opacity: 1; }
.topbar { flex-wrap: wrap; row-gap: 0; }
.topbar-actions { display: flex; gap: 0; margin-left: auto; flex-shrink: 0; }
@media (max-width: 420px) {
  .playing .title span { display: none; }
  .playing .save-status { order: 3; flex-basis: 100%; padding-bottom: .1rem; }
  .icon-btn { min-width: 42px; }
}
.icon-btn {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 8px;
  background: transparent; color: inherit; font-size: 1.35rem; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; }
.icon-btn:not(:disabled):active { background: rgba(255,255,255,.18); }

.banner { margin: .5rem .75rem 0; padding: .6rem .75rem; border-radius: var(--radius); background: #fff4d6; border: 1px solid var(--suspect); font-size: .9rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.banner.error { background: #fdecea; border-color: var(--cross); }

/* ---------- views ---------- */
main { max-width: 1100px; margin: 0 auto; padding: .75rem max(.75rem, env(safe-area-inset-left)); }
.view { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1rem .85rem; margin-bottom: .75rem; }
.view-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem .75rem; margin-bottom: .6rem; }
.view-head .hint { flex-basis: 100%; }
.count { margin: 0; font-size: .85rem; color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin: .4rem 0; }
.fineprint { color: var(--muted); font-size: .8rem; margin-top: 1rem; }

/* ---------- buttons / fields ---------- */
.btn {
  min-height: 44px; padding: .55rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 1rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.danger { color: var(--cross); border-color: #e6b7b3; }
.btn.wide { width: 100%; }
.btn:active { transform: translateY(1px); }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: .25rem; margin: .6rem 0; font-size: .9rem; color: var(--muted); }
.field > span { font-weight: 600; }
input[type=text], textarea, select {
  font: inherit; font-size: 16px; color: var(--ink);
  width: 100%; min-height: 44px; padding: .55rem .65rem;
  border: 1px solid #b9beb6; border-radius: 8px; background: #fff;
}
textarea { resize: vertical; line-height: 1.4; }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; }
legend { font-weight: 700; margin-bottom: .4rem; padding: 0; }

/* segmented radio-like buttons */
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg.col { flex-direction: column; }
.seg button {
  flex: 1 1 0; min-width: 3rem; min-height: var(--tap); padding: .4rem .6rem;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; font: inherit; color: var(--ink); cursor: pointer; text-align: center;
}
.seg.col button { text-align: left; }
.seg button[aria-checked=true] { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
.seg.small button { min-height: 44px; font-size: .9rem; }

/* ---------- setup ---------- */
.setup { max-width: 560px; margin: 0 auto .75rem; }
.setup h2 { margin-bottom: 1rem; }
.seat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.seat { display: grid; grid-template-columns: 1.6rem 1fr; gap: .35rem .5rem; align-items: center; padding: .5rem; border: 1px solid var(--line); border-radius: var(--radius); }
.seat-num { font-weight: 700; color: var(--muted); text-align: center; }
.seat-opts { grid-column: 2; display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  min-height: 44px; padding: .3rem .75rem; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font: inherit; font-size: .9rem; cursor: pointer; color: var(--ink);
}
.chip[aria-pressed=true], .chip[aria-checked=true] { background: var(--brand); color: #fff; border-color: var(--brand); }
.setup-summary { background: var(--bg); border-radius: var(--radius); padding: .6rem .75rem; font-size: .9rem; margin-bottom: 1rem; }
.setup-summary ul { margin: .25rem 0 0; padding-left: 1.1rem; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: .4rem; margin-bottom: .6rem; }
.toolbar button {
  flex: 1; min-height: var(--tap); border-radius: var(--radius); border: 1px solid var(--line);
  background: #fff; font: inherit; font-size: .95rem; cursor: pointer; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
}
.toolbar button[aria-checked=true] { border-width: 2px; border-color: var(--ink); font-weight: 700; background: var(--bg); }
.tool-ico { font-weight: 800; }
.tool-ico.x { color: var(--cross); }
.tool-ico.s { color: #9a6b00; }

/* ---------- flower grid ---------- */
.grid-head { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-bottom: .3rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; text-align: center; }
.grid-head .h { color: var(--herb-line); }
.grid-head .w { color: var(--woody-line); }
.flower-grid { max-width: 460px; }
.flower-cells { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .4rem; column-gap: .4rem; position: relative; }
.flower-cells > :nth-child(4n+3) { margin-left: .35rem; }
.flower-cells > :nth-child(4n+2) { margin-right: .35rem; }
/* dotted herbaceous | woody divider, as on the template */
.flower-cells::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; border-left: 2px dotted #333; transform: translateX(-1px); pointer-events: none; }
.flower {
  position: relative; aspect-ratio: 1; min-height: var(--tap);
  border-radius: 12px; border: 2px solid transparent; cursor: pointer;
  display: grid; place-items: center; font: inherit; color: var(--ink); padding: 0;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.flower.herbaceous { background: #fff; }
.flower.woody { background: #fff; }
.flower svg { position: absolute; inset: 8%; width: 84%; height: 84%; stroke-width: 3.5; stroke-linejoin: round; }
.flower.shape-a svg { fill: #fff; stroke: #111; }
.flower.shape-b svg { fill: #fbf5df; stroke: #8f8a74; }
.flower.shape-c svg { fill: #f7d9d6; stroke: #a8645d; }
.flower.shape-d svg { fill: #e1deec; stroke: #7d7a93; }
.flower:not(.shape-a) .num { color: #555; }
.flower .num { position: relative; font-size: clamp(1.1rem, 5vw, 1.6rem); font-weight: 700; }
.flower .badge { position: absolute; top: 3px; right: 5px; font-size: .8rem; font-weight: 800; }
.flower.mark-x { background: #ececec; }
.flower.mark-x .num { color: #8a8a8a; text-decoration: line-through; text-decoration-thickness: 3px; text-decoration-color: var(--cross); }
.flower.mark-x svg { opacity: .2; }
.flower.mark-x .badge { color: var(--cross); }
.flower.mark-s { border-color: var(--suspect); box-shadow: inset 0 0 0 2px var(--suspect); }
.flower.mark-s .badge { color: #9a6b00; }
.flower.exact { outline: 3px solid var(--brand); outline-offset: -3px; }
.flower-grid.mini .flower .num { font-size: 1.15rem; }

/* ---------- players ---------- */
.player-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.player { border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; }
.player-head { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .45rem; }
.player-name { font-weight: 700; font-size: 1rem; margin-right: auto; }
.tag { font-size: .72rem; font-weight: 700; padding: .15rem .45rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.tag.you { background: var(--brand); color: #fff; border-color: var(--brand); }
.tag.start { background: #fff4d6; border-color: var(--suspect); }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .45rem; }
.slot {
  min-height: 72px; border: 1px solid #b9beb6; border-radius: var(--radius); background: #fff;
  padding: .45rem .5rem; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  display: flex; flex-direction: column; gap: .15rem;
}
.slot-pos { font-size: .75rem; color: var(--muted); font-weight: 600; }
.slot-val { font-size: 1.05rem; font-weight: 700; }
.slot-meta { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.slot.st-exact { border-left: 5px solid var(--brand); }
.slot.st-suspect { border-left: 5px solid var(--suspect); }
.slot.st-suspect .slot-val { color: #9a6b00; }
.slot-val.many { font-size: .9rem; overflow-wrap: anywhere; }
.dir { font-size: .75rem; color: var(--muted); margin: .1rem 0 .35rem; }

/* ---------- notes / clues ---------- */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.row2 .field { margin: .3rem 0; }
.clue-form .seg { margin: .4rem 0 .6rem; }
.clue-list { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-direction: column; gap: .4rem; }
.clue { border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem .6rem; display: grid; grid-template-columns: 1fr auto; gap: .2rem .5rem; align-items: start; }
.clue-meta { font-size: .75rem; color: var(--muted); }
.clue-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.clue.private { background: #fbfaf5; border-style: dashed; }
.clue-actions { grid-row: span 2; display: flex; gap: .25rem; }
.clue-actions button { min-width: 44px; min-height: 44px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font: inherit; }
.empty { color: var(--muted); font-size: .9rem; font-style: italic; }
.inline-add { display: flex; gap: .4rem; margin-top: .5rem; }
.inline-add input { flex: 1; min-width: 0; }

/* ---------- bottom tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
}
.tabs button { border: 0; background: none; font: inherit; font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; cursor: pointer; }
.tabs button span { font-size: 1.3rem; line-height: 1; }
.tabs button[aria-current=page] { color: var(--brand); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }

/* ---------- dialogs (bottom sheet on phones) ---------- */
dialog.sheet {
  border: 0; padding: 0; width: 100%; max-width: 560px;
  max-height: min(92dvh, 100%); margin: auto auto 0; border-radius: 16px 16px 0 0;
  background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(20, 30, 25, .45); }
.sheet-inner { display: flex; flex-direction: column; max-height: 92dvh; }
dialog.sheet[open] { overflow: hidden; }
.sheet-head { position: sticky; top: 0; z-index: 2; background: var(--surface); flex: none; }
.sheet-body { flex: 1 1 auto; min-height: 0; }
.sheet-foot { flex: none; }
.sheet-head { display: flex; align-items: center; gap: .5rem; padding: .6rem .85rem; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; font-size: 1.05rem; }
.sheet-body { overflow-y: auto; padding: .75rem .85rem calc(1rem + var(--safe-b)); overscroll-behavior: contain; }
.sheet-foot { display: flex; gap: .5rem; padding: .6rem .85rem calc(.6rem + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-foot:empty { display: none; }
.sheet-foot .btn { flex: 1; }
.menu { display: flex; flex-direction: column; gap: .5rem; }
.rules h3 { margin-top: 1rem; }
.rules p, .rules li { font-size: .95rem; line-height: 1.45; }
.rules ul { padding-left: 1.2rem; }
.src { color: var(--muted); font-size: .78rem; }
.rename-list { display: flex; flex-direction: column; gap: .2rem; }

/* ---------- privacy cover ---------- */
.cover {
  position: fixed; inset: 0; z-index: 100; background: var(--brand); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 2rem; text-align: center;
}
.cover .btn.primary { background: #fff; color: var(--brand); font-size: 1.1rem; padding: .8rem 1.5rem; }

/* ---------- wider screens: show sections side by side ---------- */
@media (min-width: 820px) {
  body { padding-bottom: 1rem; }
  .tabs { display: none !important; }
  main.playing { display: grid; grid-template-columns: minmax(340px, 460px) 1fr; gap: .75rem; align-items: start; }
  main.playing .view { display: block !important; margin: 0; }
  main.playing #view-flowers { grid-row: span 2; position: sticky; top: 70px; }
  dialog.sheet { margin: auto; border-radius: 16px; }
}

@media (prefers-reduced-motion: no-preference) {
  dialog.sheet[open] { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } }
}

/* player header: rename + You/Starts toggles */
.player-head { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.player-name.rename { flex: 1 1 8rem; text-align: left; background: none; border: 0; padding: .35rem 0; font: inherit; font-weight: 700; color: inherit; cursor: pointer; min-height: 44px; }
.player-head .chip { min-height: 40px; padding: .3rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: .9rem; }
.player-head .chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
label.check { display: flex; align-items: center; gap: .5rem; min-height: 44px; margin-top: .5rem; }
label.check input { width: 1.3rem; height: 1.3rem; }
