:root {
  --bg-1: #eef2fb;
  --bg-2: #f1f6fc;
  --panel: #ffffff;
  --border: #dde4f0;
  --border-strong: #c5cee0;
  --text: #1e2837;
  --muted: #6b7585;
  --brand: #2f74d0;
  --brand-2: #4f8ee0;
  --brand-dark: #1f5bab;
  --tint: #e8f0fc;
  --danger: #e11d48;
  --ok: #15803d;
  --shadow-sm: 0 1px 2px rgba(30,40,60,.06);
  --shadow-md: 0 6px 16px rgba(30,40,60,.09);
  --shadow-lg: 0 20px 44px rgba(30,50,90,.16);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ===== Header ===== */
header.app-header {
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 13px 22px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 40;
}
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--text); }
.brand-mark {
  font-size: 20px; line-height: 1; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--tint); border: 1px solid #bcd3f3; border-radius: 9px;
}
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: .02em; }
.topnav { display: flex; gap: 6px; }
.topnav-btn {
  font-size: 13px; font-weight: 700; padding: 6px 11px; border-radius: 8px;
  text-decoration: none; color: var(--brand-dark); border: 1px solid transparent;
}
.topnav-btn.link:hover { background: var(--tint); border-color: #bcd3f3; }
.topnav-btn.active { background: var(--brand); color: #fff; }
.app-header .spacer { flex: 1; }
.privacy-badge {
  font-size: 12px; color: var(--ok); font-weight: 700;
  background: #e9f8ef; border: 1px solid #b7e6c8; padding: 4px 10px; border-radius: 8px; white-space: nowrap;
}
.counter {
  font-size: 13px; color: var(--brand-dark); font-weight: 700;
  background: var(--tint); border: 1px solid #bcd3f3; padding: 4px 11px; border-radius: 8px; white-space: nowrap;
}
.counter.live { color: #fff; background: var(--ok); border-color: var(--ok); }
.counter.busy { color: #fff; background: var(--brand); border-color: var(--brand); }

/* ===== Buttons ===== */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  box-shadow: var(--shadow-sm); transition: .12s;
}
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand-dark); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.big { font-size: 16px; padding: 13px 22px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ===== Intro ===== */
.intro { display: flex; justify-content: center; padding: 48px 18px; }
.intro-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 38px 36px; max-width: 640px; text-align: center;
}
.intro-card h1 { font-size: 24px; margin: 0 0 14px; }
.intro-card p { color: var(--muted); line-height: 1.8; margin: 0 0 20px; }
.intro-card .hint { font-size: 13px; margin-top: 22px; }
.intro-card strong { color: var(--text); }

/* ===== Toolbar ===== */
.toolbar {
  position: sticky; top: 60px; z-index: 30;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 11px 22px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
}
.toolbar .group { display: inline-flex; align-items: center; gap: 8px; }
.toolbar .spacer { flex: 1; }
.group-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.sel { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border-strong); background: #fff; }
.chk { font-size: 13px; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }

/* ===== Stage / work ===== */
.stage-wrap { display: flex; gap: 18px; padding: 20px 22px; align-items: flex-start; flex-wrap: wrap; }
.stage {
  position: relative; flex: 1 1 560px; min-width: 320px;
  background: #0e1726; border: 1px solid var(--border-strong); border-radius: 14px;
  overflow: hidden; box-shadow: var(--shadow-md); line-height: 0;
}
#video { width: 100%; display: block; }
.stage-tip {
  position: absolute; left: 0; right: 0; bottom: 0; line-height: 1.5;
  background: rgba(14,23,38,.82); color: #dce7f7; font-size: 12px; padding: 8px 12px;
}
.selbox {
  position: absolute; left: 8%; top: 35%; width: 38%; height: 16%;
  border: 2.5px solid #38bdf8; background: rgba(56,189,248,.14);
  box-shadow: 0 0 0 9999px rgba(8,14,24,.35); cursor: move; border-radius: 4px;
}
.sel-label {
  position: absolute; top: -22px; left: 0; font-size: 11px; line-height: 1;
  background: #38bdf8; color: #06263a; font-weight: 800; padding: 4px 7px; border-radius: 5px; white-space: nowrap;
}
.handle {
  position: absolute; width: 18px; height: 18px; background: #38bdf8;
  border: 2px solid #fff; border-radius: 50%;
}
.handle.se { right: -10px; bottom: -10px; cursor: nwse-resize; }

/* ===== Result pane ===== */
.result-pane {
  flex: 0 0 320px; display: flex; flex-direction: column; gap: 16px;
}
.read-now { width: 100%; }
.latest-label { font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.latest, .ocr-preview, .history {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.latest-value {
  font-size: 30px; font-weight: 800; letter-spacing: .04em; color: var(--brand-dark);
  word-break: break-all; min-height: 38px; font-variant-numeric: tabular-nums;
}
.latest-value.flash { animation: flash .6s ease; }
@keyframes flash { 0% { background: #fff7c2; } 100% { background: transparent; } }
.copy-again { margin-top: 10px; }
#cropCanvas { width: 100%; background: #f4f7fc; border: 1px solid var(--border); border-radius: 8px; image-rendering: pixelated; }
.history ul { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; }
.history li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 6px; border-bottom: 1px dashed var(--border); cursor: pointer; font-size: 15px;
}
.history li:hover { background: var(--tint); }
.history li .num { font-weight: 700; letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.history li .time { font-size: 11px; color: var(--muted); }
.history li.empty { color: var(--muted); cursor: default; font-size: 13px; }
.history li.empty:hover { background: none; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px);
  background: #0e1726; color: #fff; padding: 12px 22px; border-radius: 10px;
  font-weight: 700; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: .22s; z-index: 90; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

@media (max-width: 860px) {
  .result-pane { flex: 1 1 100%; }
}
