:root {
  --paper: #f1f4f2;
  --ink: #13232b;
  --water: #0b6b72;
  --water-dark: #084f54;
  --signal: #f2a900;
  --stop: #c8452f;
  --fog: #dde5e2;
  --slate: #5b6c72;
  --ok: #2e8b57;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1a1f;
    --ink: #e8efec;
    --water: #3fb7bf;
    --water-dark: #7fd4da;
    --fog: #223239;
    --slate: #9db0b6;
    --stop: #ff7a62;
    --ok: #62c98f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.55;
}
#app { min-height: 100%; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; }

/* แถบสถานะด้านบน */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--paper); border-bottom: 1px solid var(--fog);
  padding-top: max(10px, env(safe-area-inset-top));
}
.top .brand { font-weight: 700; margin-right: auto; }
@media (max-width: 479px) { .top .brand { display: none; } .top { justify-content: space-between; } }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--slate); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--fog); border: 1px solid var(--slate); }
.dot.on { background: var(--ok); border-color: var(--ok); }
.dot.warn { background: var(--signal); border-color: var(--signal); }

main { flex: 1; padding: 20px 16px 110px; }
h1 { font-size: 26px; line-height: 1.25; margin: 4px 0 6px; }
h2 { font-size: 20px; margin: 28px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 4px; color: var(--slate); font-weight: 600; }
p { margin: 8px 0; }
.sub { color: var(--slate); font-size: 15px; }
section + section { margin-top: 28px; padding-top: 4px; border-top: 1px solid var(--fog); }

/* แถบเมนูล่าง */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; max-width: 720px; margin: 0 auto;
  background: var(--paper); border-top: 1px solid var(--fog);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1; min-height: 58px; border: 0; background: none; color: var(--slate);
  font: inherit; font-size: 15px; cursor: pointer; position: relative;
}
nav.tabs button[aria-current="page"] { color: var(--ink); font-weight: 700; }
nav.tabs button[aria-current="page"]::after {
  content: ""; position: absolute; left: 22%; right: 22%; top: 0; height: 3px; background: var(--water);
}

/* ปุ่ม / ฟอร์ม */
button.btn {
  min-height: 52px; padding: 0 20px; border-radius: 10px; border: 2px solid var(--water);
  background: var(--water); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
@media (prefers-color-scheme: dark) { button.btn { color: #06282b; } }
button.btn.ghost { background: transparent; color: var(--water-dark); }
button.btn.danger { background: transparent; border-color: var(--stop); color: var(--stop); }
button.btn.small { min-height: 42px; padding: 0 14px; font-size: 15px; }
button.btn.block { width: 100%; }
button.btn:disabled { opacity: .45; cursor: not-allowed; }
button.btn:focus-visible, input:focus-visible, select:focus-visible, nav.tabs button:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }
label { display: block; font-size: 15px; color: var(--slate); margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=email], select {
  width: 100%; min-height: 50px; padding: 0 14px; font: inherit; color: var(--ink);
  background: transparent; border: 2px solid var(--fog); border-radius: 10px;
}
input[type=range] { width: 100%; accent-color: var(--water); height: 36px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.err { color: var(--stop); font-weight: 600; margin: 10px 0; }
.ok { color: var(--ok); font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; }

/* รายการ (เส้นคั่นแทนการ์ด) */
ul.list { list-style: none; margin: 8px 0; padding: 0; }
ul.list > li { padding: 12px 0; border-bottom: 1px solid var(--fog); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
ul.list > li .main { flex: 1; min-width: 140px; }
ul.list > li .main b { display: block; }

/* หน้า "สด": คำที่ถุงมือเพิ่งพูด */
.stage {
  min-height: 42vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px 12px; border-radius: 6px; transition: background .25s, color .25s;
  border: 2px solid var(--fog); word-break: keep-all;
}
.stage .word { font-size: clamp(56px, 20vw, 150px); font-weight: 700; line-height: 1.1; }
.stage .meta { color: var(--slate); font-size: 16px; min-height: 1.6em; }
.stage.hit { background: var(--signal); border-color: var(--signal); color: #1b1300; }
.stage.hit .meta { color: #1b1300; }
.wordbtns { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 10px; }

/* แถบเซนเซอร์ */
.bars { display: grid; gap: 8px; margin: 12px 0; }
.bar { display: flex; align-items: center; gap: 10px; }
.bar .lbl { width: 54px; font-size: 14px; color: var(--slate); }
.bar .track { flex: 1; height: 14px; background: var(--fog); border-radius: 7px; overflow: hidden; }
.bar .fill { height: 100%; width: 0; background: var(--water); }
.bar .track { position: relative; }
.bar.signed .fill { position: absolute; top: 0; bottom: 0; left: 50%; height: auto; }
.bar.signed .track::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--slate); opacity: .6; }
.bar .val { width: 52px; text-align: right; font-size: 14px; }

/* ตัวนับถอยหลังตอนบันทึกท่า */
.recorder { text-align: center; padding: 22px 8px; border: 2px solid var(--water); border-radius: 6px; margin: 16px 0; }
.recorder .count { font-size: clamp(72px, 28vw, 160px); font-weight: 700; line-height: 1; }
.recorder.go { background: var(--signal); border-color: var(--signal); color: #1b1300; }
.progress { height: 10px; background: var(--fog); border-radius: 5px; overflow: hidden; margin: 12px 0; }
.progress > i { display: block; height: 100%; background: var(--water); width: 0; transition: width .15s; }

table.cm { border-collapse: collapse; font-size: 13px; margin: 10px 0; }
table.cm td, table.cm th { padding: 4px 8px; text-align: center; border: 1px solid var(--fog); }
table.cm td.diag { font-weight: 700; background: color-mix(in srgb, var(--water) 18%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.pill { font-size: 14px; padding: 2px 10px; border: 1px solid var(--fog); border-radius: 12px; }
.pill.on { border-color: var(--ok); color: var(--ok); }
.pill.miss { border-color: var(--stop); color: var(--stop); }
.level { height: 10px; background: var(--fog); border-radius: 5px; overflow: hidden; }
.level > i { display: block; height: 100%; width: 0; background: var(--ok); }

.login { max-width: 420px; margin: 12vh auto 0; padding: 0 20px; }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 10;
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 10px; max-width: 90%;
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
