:root {
  --bg: #f3f1ea;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6b66;
  --felt: #0f5132;
  --felt-2: #157347;
  --accent: #c8102e;
  --line: #e2ded3;
  --tile: #fbf8ef;
  --tile-edge: #cfc6ad;
  --man: #1d1d1b;
  --pin: #1f4fa8;
  --sou: #157347;
  --good: #157347;
  --warn: #b26b00;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412; --card: #1c1f1c; --ink: #ecebe6; --muted: #a4a39c; --line: #2e322e;
    --tile: #f4efe1; --tile-edge: #8f8770;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--felt); color: #fff;
}
.topbar h1 { font-size: 1.1rem; margin: 0; letter-spacing: .05em; }
.badge { font-size: .75rem; padding: 2px 10px; border-radius: 999px; background: rgba(255,255,255,.18); }
.badge.live { background: var(--accent); }
main { max-width: 640px; margin: 0 auto; padding: 12px 16px; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
h2 { font-size: 1rem; margin: 0 0 8px; }
h2 small { color: var(--muted); font-weight: normal; margin-left: 6px; }
h3 { font-size: .9rem; margin: 12px 0 6px; color: var(--muted); }
button, select, input[type=number] {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
button { cursor: pointer; touch-action: manipulation; }
button.primary { background: var(--felt-2); color: #fff; border-color: transparent; font-weight: 600; }
button[aria-pressed=true] { background: var(--accent); color: #fff; border-color: transparent; }
.row { display: flex; gap: 8px; margin-top: 8px; }
.row > button { flex: 1; }
.viewport { position: relative; aspect-ratio: 4 / 3; max-height: 62vh; margin: 0 auto; background: #0b0d0b; border-radius: 10px; overflow: hidden; }
video, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.camera-hint { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; text-align: center; color: #cfd8cf; font-size: .9rem; }
.note { font-size: .85rem; color: var(--warn); margin: 8px 0 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mini-actions { display: flex; gap: 6px; }
.mini-actions button { min-height: 36px; padding: 4px 10px; font-size: .85rem; }

.tiles { display: flex; flex-wrap: wrap; gap: 3px; min-height: 52px; align-items: flex-end; }
.tiles.small { min-height: 0; display: inline-flex; vertical-align: middle; }
.tile {
  width: 34px; height: 46px; border-radius: 5px; background: var(--tile); border: 1px solid var(--tile-edge);
  box-shadow: 0 2px 0 var(--tile-edge); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; line-height: 1; user-select: none; padding: 0; min-height: 0; color: var(--man);
}
.tile .n { font-size: 1.05rem; }
.tile .s { font-size: .7rem; margin-top: 3px; }
.tile.p { color: var(--pin); } .tile.s { color: var(--sou); }
.tile.z .n { font-size: 1.25rem; } .tile.z .s { display: none; }
.tile.red, .tile.z7 { color: var(--accent); }
.tile.z6 { color: var(--sou); }
.tile.selected { outline: 3px solid var(--accent); outline-offset: 1px; }
.tile.win { box-shadow: 0 2px 0 var(--tile-edge), 0 0 0 2px var(--warn); }
.tile.img { overflow: hidden; position: relative; }
.tile.img .n, .tile.img .s { display: none; }
.tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tile.img.red::after { content: "赤"; position: absolute; right: 1px; top: 1px; font-size: 8px; line-height: 1; padding: 1px 2px; border-radius: 3px; background: var(--accent); color: #fff; }
.tiles.small .tile.img.red::after { display: none; }
.tiles.small .tile { width: 26px; height: 35px; } .tiles.small .tile .n { font-size: .85rem; } .tiles.small .tile .s { font-size: .55rem; }
.hand .tile { width: calc((100% - 13 * 3px) / 14); max-width: 40px; height: auto; aspect-ratio: 3 / 4; }
.dora-line { margin-top: 10px; font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.target-switch { display: flex; gap: 16px; margin: 10px 0 6px; font-size: .9rem; }
.palette { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.palette .tile { width: 100%; height: auto; aspect-ratio: 3 / 4; }
.palette .tile:active { transform: translateY(2px); box-shadow: none; }

.settings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: .85rem; }
.settings label { display: grid; gap: 4px; }
.settings label.check { display: flex; align-items: center; gap: 6px; font-size: .95rem; }
.settings input[type=checkbox] { width: 22px; height: 22px; }
.settings select, .settings input[type=number] { width: 100%; }

.message { font-size: 1.05rem; font-weight: 600; margin: 0; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.list li.best { border-color: var(--good); background: color-mix(in srgb, var(--good) 8%, transparent); }
.list .meta { font-size: .85rem; color: var(--muted); }
.list .pts { margin-left: auto; font-weight: 700; white-space: nowrap; }
.score-box { border: 2px solid var(--accent); border-radius: 12px; padding: 10px; margin-top: 10px; }
.score-box .big { font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.score-box ul { margin: 6px 0 0; padding-left: 1.2em; }
.hint .dist { font-size: .8rem; padding: 2px 8px; border-radius: 999px; background: var(--line); white-space: nowrap; }
.hint .dist.ok { background: var(--good); color: #fff; }
.err { color: var(--accent); }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 8px 16px 24px; }
@media (max-width: 380px) { .settings { grid-template-columns: repeat(2, 1fr); } }
.nowrap { white-space: nowrap; }
.status { font-size: .85rem; margin: 8px 0 0; color: var(--muted); }
.tip { font-size: .8rem; color: var(--muted); margin: 6px 0 0; }
.manual { color: var(--warn); font-weight: 600; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 600px; margin: 0 auto; padding: 12px 14px; border-radius: 12px; background: #1d1d1b; color: #fff;
  font-size: .9rem; opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--accent); }
[hidden] { display: none !important; }
.players-switch { display: flex; gap: 16px; margin: 0 0 10px; font-size: .95rem; font-weight: 600; }
h3.sub { color: var(--ink); margin: 14px 0 6px; font-size: .95rem; }
h3.sub small { color: var(--muted); font-weight: normal; font-size: .78rem; margin-left: 4px; }
.meld-buttons button { min-height: 40px; padding: 6px 8px; }
.melds { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.meld { display: flex; align-items: center; gap: 6px; padding: 4px 8px; min-height: 0; }
.dora-slots { display: flex; flex-wrap: wrap; gap: 6px; }
.dora-slot { display: flex; align-items: center; gap: 6px; padding: 6px 10px; min-height: 44px; }
.dora-slot.picking, .pick-banner { outline: 3px solid var(--accent); }
label.inline { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .85rem; color: var(--muted); }
label.inline input, label.inline select { width: auto; min-width: 72px; }
.pick-banner {
  position: sticky; top: 52px; z-index: 5; display: flex; align-items: center; gap: 8px; margin: 10px 0 6px;
  padding: 8px 10px; border-radius: 10px; background: var(--card); font-size: .88rem; font-weight: 600;
}
.pick-banner span { flex: 1; }
.pick-banner button { min-height: 36px; padding: 4px 10px; }
#rulesCard summary { cursor: pointer; list-style: none; }
#rulesCard summary h2 { display: inline; }
#rulesCard summary::after { content: " ▼"; color: var(--muted); font-size: .8rem; }
#rulesCard[open] summary::after { content: " ▲"; }
.rule-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 12px; margin: 10px 0; font-size: .9rem; }
.rule-list label.check { display: flex; align-items: center; gap: 6px; }
.rule-list input[type=checkbox] { width: 22px; height: 22px; }

/* 使い方 */
.guide summary { font-weight: 700; cursor: pointer; padding: 2px 0; }
.steps { margin: 8px 0 0; padding-left: 1.4em; display: grid; gap: 8px; font-size: .9rem; }
.steps li { padding: 6px 8px; border-radius: 8px; }
.steps li.now { background: color-mix(in srgb, var(--good) 14%, transparent); outline: 2px solid var(--good); }
.steps a { color: var(--felt-2); margin-left: 4px; white-space: nowrap; }
.cam-controls { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: .85rem; }
.cam-controls label { display: grid; gap: 4px; flex: 1 1 140px; }
.cam-controls select { width: 100%; }
.status.warn { color: var(--warn); font-weight: 600; }
.cam-buttons { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1 1 100%; }
.cam-buttons button { min-height: 38px; padding: 6px 10px; font-size: .85rem; }
.inline-check { display: inline-flex !important; align-items: center; gap: 4px; }
.debug { font-size: .75rem; color: var(--muted); margin: 6px 0 0; font-family: ui-monospace, monospace; }
.tile.unsure { outline: 2px dashed var(--warn); outline-offset: 1px; }
button.ok { background: var(--accent); color: #fff; border-color: transparent; font-weight: 700; }
.locked { color: var(--good); font-weight: 700; }
/* 点数（ロン・ツモ） */
.score-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 420px) { .score-pair { grid-template-columns: 1fr; } }
.score-box { border-color: var(--line); }
.score-box.selected { border-color: var(--accent); }
.score-title { font-size: .85rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.score-box .pays { list-style: none; padding: 0; margin: 4px 0; font-weight: 700; }
.score-box .hanfu { font-size: .9rem; }
.score-box details.fu { margin-top: 8px; font-size: .85rem; }
.score-box details.fu summary { cursor: pointer; color: var(--felt-2); font-weight: 600; }
.score-box details.fu table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.score-box details.fu td { padding: 3px 2px; border-bottom: 1px solid var(--line); }
.score-box details.fu td:last-child { text-align: right; white-space: nowrap; }
.score-box details.fu tr.sum td { font-weight: 700; border-bottom: none; }
.pts.two { text-align: right; line-height: 1.35; }
.pts.two .sub { font-weight: 600; font-size: .85rem; color: var(--muted); }
.special { margin-top: 10px; font-size: .9rem; }
.special summary { cursor: pointer; font-weight: 600; }
.special label.check small { display: block; color: var(--muted); font-size: .72rem; font-weight: normal; }
.special label.check { align-items: flex-start !important; }
.other-pay { margin: 4px 0 6px; padding: 6px 8px; border-radius: 8px; background: var(--line); font-size: .85rem; }
.other-pay ul { list-style: none; padding: 0; margin: 2px 0 0; font-weight: 600; }
.dealer-switch { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.dealer-switch button { min-height: 38px; padding: 6px 12px; }

/* ---------- スマートグラス表示 ---------- */
.glass-btn { margin-left: auto; margin-right: 8px; min-height: 34px; padding: 4px 10px; font-size: .8rem; background: #000; color: #fff; border-color: #444; }
/* 通常の画面は見えない所へ移す（カメラ映像の取り込みは続けるため display:none にはしない） */
body.glasses { background: #000; overflow: hidden; }
body.glasses .topbar, body.glasses .foot { display: none; }
body.glasses main { position: fixed; left: -10000px; top: 0; width: 390px; pointer-events: none; }
/* カメラ映像は小さく右下に残す（狙いを合わせる用。映像が止まらないよう画面内に置く） */
body.glasses #viewport { position: fixed; left: auto; right: 8px; bottom: 60px; width: 96px; max-height: 30vh; z-index: 60; opacity: .55; border-radius: 6px; }
body.glasses #viewport[hidden] { display: none !important; }
body.glasses #cameraHint { display: none; }
.glass { position: fixed; inset: 0; z-index: 50; background: #000; color: #f2f2f2; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.g-frame { flex: 1; width: 100%; max-width: calc(100vh * 16 / 9); margin: 0 auto; display: flex; flex-direction: column;
  justify-content: center; gap: 2.2vh; padding: 3vh 3vw; cursor: pointer; }
.g-status { color: #7a7a7a; font-size: clamp(11px, 2.4vh, 16px); text-align: center; }
.g-hand { display: flex; flex-wrap: nowrap; justify-content: center; align-items: flex-end; gap: 0.6%; }
.g-hand > .tile { width: calc((100% - 13 * 0.6%) / 14); max-width: 72px; height: auto; aspect-ratio: 3 / 4; border-radius: 6px; box-shadow: none; border: none; }
.g-melds { margin-left: 2%; display: inline-flex; gap: 4px; }
.g-melds .tile { width: 22px; height: 30px; }
.g-empty { color: #888; font-size: clamp(14px, 3vh, 22px); }
.g-main { text-align: center; font-weight: 800; }
.g-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; font-size: clamp(14px, 3vh, 22px); color: #e8e8e8; }
.g-big { font-size: clamp(18px, 4.6vh, 34px); color: #fff; }
.g-big.ok { color: #5dff9a; }
.g-main .tiles.small .tile { width: clamp(28px, 6vh, 46px); height: auto; aspect-ratio: 3 / 4; }
.g-sub { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; }
.g-hint { font-size: clamp(13px, 2.8vh, 20px); color: #bdbdbd; white-space: nowrap; }
.g-hint.ok { color: #5dff9a; }
.g-score { border-top: 1px solid #333; padding-top: 1.5vh; display: grid; gap: 6px; }
.g-score .g-line { font-weight: 700; color: #ffd75e; }
.g-tap { text-align: center; color: #555; font-size: 11px; }
.g-controls { display: flex; gap: 8px; justify-content: center; padding: 8px; }
.g-controls button { background: #111; color: #9a9a9a; border-color: #333; min-height: 40px; font-size: .85rem; }
