:root {
  --bg: #f6f1e8;
  --paper: #fffdf8;
  --ink: #1b1713;
  --muted: #7a7166;
  --line: #e6dccb;
  --left: #c2452d;
  --right: #2a5f8f;
  --ok: #2f7d4a;
  --warn: #9a6b12;
  --accent: #c2452d;
  --shadow: 0 10px 30px rgba(40, 28, 16, .06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -10%, #fff7ea, transparent 55%),
    var(--bg);
  font: 16px/1.5 "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 40; padding: 12px 14px; border-radius: 12px;
  background: #2a2218; color: #fff8ec; box-shadow: var(--shadow);
}
.toast.bad { background: #6d2a22; }
.toast.ok { background: #1f4a30; }

#login {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 20px calc(32px + env(safe-area-inset-bottom));
}
.login-card {
  width: min(420px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px 24px 28px;
  box-shadow: var(--shadow);
}
.mark {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: .08em;
}
.brand { margin: 18px 0 6px; font-size: 30px; letter-spacing: .06em; }
.lead { margin: 0 0 8px; color: var(--muted); }
label { display: block; margin: 18px 0 8px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password] {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
input[type=text]:focus, input[type=password]:focus { outline: 2px solid #ead3c6; border-color: #d7b7a6; }
.primary {
  width: 100%; margin-top: 22px; border: 0; border-radius: 12px;
  padding: 14px 16px; background: var(--ink); color: #fff; font-weight: 650;
}
.primary:disabled { opacity: .5; }
.field-error { min-height: 22px; margin-top: 10px; color: var(--accent); font-size: 14px; }
.fine { margin: 18px 0 0; color: var(--muted); font-size: 12px; }
.fine a { color: var(--ink); }

.capture-src {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 4px;
  height: 4px;
  opacity: 0.02;
  pointer-events: none;
  z-index: 0;
  object-fit: cover;
}
.offscreen-canvas {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}

#login, #app { position: relative; z-index: 1; }
#app { min-height: 100%; display: flex; flex-direction: column; }
.top {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 8px;
}
.me {
  display: flex; align-items: center; gap: 12px;
  border: 0; background: none; color: inherit; text-align: left; padding: 4px 0;
}
.me strong { display: block; letter-spacing: .08em; }
.avatar {
  width: 40px; height: 40px; border-radius: 14px;
  background: var(--ink); color: #fff8ec;
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: .04em;
}
.avatar.lg { width: 64px; height: 64px; border-radius: 20px; font-size: 24px; margin: 0 auto 10px; }
.who { display: block; color: var(--muted); font-size: 13px; }

.board {
  position: relative;
  flex: 1;
  margin: 8px 16px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  overflow: hidden;
  min-height: 280px;
}
.seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 12px;
  transition: background .35s ease, transform .35s ease;
}
.seat.left { background: linear-gradient(180deg, rgba(194,69,45,.08), transparent 70%); }
.seat.right { background: linear-gradient(180deg, rgba(42,95,143,.08), transparent 70%); }
.seat-name { font-size: 13px; letter-spacing: .18em; color: var(--muted); }
.seat-score { font-size: 56px; font-weight: 800; line-height: 1; margin: 8px 0 6px; }
.seat.left .seat-score { color: var(--left); }
.seat.right .seat-score { color: var(--right); }
.seat-rank {
  font-size: 18px;
  font-weight: 700;
  min-height: 1.4em;
}
body:not(.reveal) .seat-rank { visibility: hidden; }
.seat-tag {
  margin-top: 10px;
  min-height: 28px;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: .12em;
}
.callout {
  width: min(42vw, 220px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px 8px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.call-main { font-size: 28px; font-weight: 800; letter-spacing: .08em; }
.call-sub { margin-top: 8px; color: var(--muted); font-size: 14px; min-height: 2.8em; }
.call-meta { margin-top: 10px; color: var(--muted); font-size: 12px; }

.board.win-left .seat.left {
  background: linear-gradient(180deg, rgba(194,69,45,.22), rgba(194,69,45,.04));
  animation: pulse-win .7s ease;
}
.board.win-left .seat.right { opacity: .42; }
.board.win-left .seat-tag#leftTag { color: var(--left); }
.board.win-right .seat.right {
  background: linear-gradient(180deg, rgba(42,95,143,.22), rgba(42,95,143,.04));
  animation: pulse-win .7s ease;
}
.board.win-right .seat.left { opacity: .42; }
.board.win-right .seat-tag#rightTag { color: var(--right); }
.board.win-both .seat { animation: pulse-die .7s ease; }
.board.win-both .seat-tag { color: var(--warn); }
.board.miss .call-main { color: var(--muted); font-size: 20px; font-weight: 650; letter-spacing: 0; }

.fx {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  opacity: 0;
}
.fx.show { animation: fx-pop 1.1s ease; }
.fx-banner {
  padding: 14px 28px;
  border-radius: 999px;
  background: rgba(27,23,19,.88);
  color: #fff8ec;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: .14em;
  box-shadow: 0 12px 40px rgba(27,23,19,.28);
}
.fx.left .fx-banner { background: rgba(194,69,45,.92); }
.fx.right .fx-banner { background: rgba(42,95,143,.92); }
.fx.both .fx-banner { background: rgba(154,107,18,.94); }

@keyframes pulse-win {
  0% { transform: scale(.97); }
  55% { transform: scale(1.03); }
  100% { transform: scale(1); }
}
@keyframes pulse-die {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@keyframes fx-pop {
  0% { opacity: 0; transform: scale(.86); }
  18% { opacity: 1; transform: scale(1.04); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

.debug-panel {
  margin: 0 16px 8px;
  background: #111;
  border-radius: 18px;
  overflow: hidden;
}
.debug-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #111;
}
.preview-canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.guides {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; justify-content: center; align-items: center;
  gap: 16%;
  padding: 22% 16% 28%;
}
.slot {
  width: 17%;
  aspect-ratio: 16 / 26;
  border: 1.5px solid rgba(255,255,255,.72);
  border-radius: 10px;
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 8px;
}
.slot i {
  font-style: normal; font-size: 12px; letter-spacing: .12em;
  color: #fff; background: rgba(0,0,0,.35); padding: 3px 8px; border-radius: 999px;
}
.flip {
  position: absolute; top: 12px; right: 12px; z-index: 3;
  border: 0; border-radius: 999px; padding: 8px 12px;
  background: rgba(0,0,0,.45); color: #fff; font-size: 13px;
}
.debug-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: #1b1713;
  color: #fff8ec;
}
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 0; color: #fff8ec; }
.switch input { width: 18px; height: 18px; }
.debug-row .dock-sub { margin: 0; color: #ffe7c2; width: auto; }
.logline {
  margin: 0;
  padding: 8px 14px 12px;
  background: #1b1713;
  color: #cbbba6;
  font-size: 12px;
  word-break: break-all;
}

.dock {
  margin-top: auto;
  flex-shrink: 0;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
}
.shoot {
  width: 100%; border: 0; border-radius: 16px;
  padding: 16px 16px; background: var(--accent); color: #fff;
  font-size: 20px; font-weight: 800; letter-spacing: .12em;
}
.shoot:disabled { opacity: .45; }
#app[data-mode="idle"] .shoot,
#app[data-mode="finished"] .shoot { background: var(--ink); }
.dock-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
#app[data-mode="idle"] #playActions,
#app[data-mode="finished"] #playActions { display: none; }
#app[data-mode="playing"] #idleActions { display: none; }
.ghost {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 12px;
  font-weight: 650;
}
.ghost:disabled { opacity: .4; }
.dock-sub {
  width: 100%; margin-top: 10px; border: 0; background: none;
  color: var(--muted); padding: 8px;
}

.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(27, 23, 19, .42);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}
.sheet-card {
  width: min(520px, 100%);
  max-height: min(86dvh, 760px);
  overflow: auto;
  background: var(--paper);
  border-radius: 24px 24px 18px 18px;
  padding: 18px 18px 22px;
  box-shadow: var(--shadow);
}
.sheet-close {
  float: right; border: 0; background: none; color: var(--muted); padding: 4px 0;
}
.profile-hero { text-align: center; padding: 8px 8px 4px; }
.profile-hero h2 { margin: 0; font-size: 24px; }
.muted { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin: 18px 0;
}
.stats div {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 10px; text-align: center;
}
.stats b { display: block; font-size: 26px; }
.stats span { color: var(--muted); font-size: 12px; }
.sheet-h { margin: 8px 0 10px; font-size: 14px; color: var(--muted); font-weight: 650; }
.month-nav {
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; margin-bottom: 8px;
}
.month-nav .text-btn { border: 0; background: none; color: var(--muted); padding: 6px 0; }
.month-nav .text-btn:last-child { text-align: right; }
.month-nav strong { letter-spacing: .06em; }
.weekdays, .month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.weekdays span { text-align: center; color: var(--muted); font-size: 12px; }
.day {
  border: 0; background: transparent; color: var(--ink);
  border-radius: 10px; min-height: 36px; position: relative; padding: 4px 0 8px;
}
.day.muted { color: #c4b8a8; }
.day.has { font-weight: 750; }
.day.has::after {
  content: ""; position: absolute; left: 50%; bottom: 4px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
  transform: translateX(-50%);
}
.day.on { background: var(--ink); color: #fff8ec; }
.day.on.has::after { background: #fff8ec; }
.day.today { box-shadow: inset 0 0 0 1px var(--line); }
.history { display: flex; flex-direction: column; gap: 8px; min-height: 48px; margin-top: 12px; }
.st { font-size: 12px; color: var(--muted); }
.st.live { color: var(--ok); font-weight: 700; }
.detail-sheet { z-index: 28; align-items: center; }
.detail-head { padding: 8px 36px 12px 0; }
.detail-head h2 { margin: 0; font-size: 28px; letter-spacing: .04em; }
.steps { display: flex; flex-direction: column; gap: 8px; }
.step {
  display: grid; grid-template-columns: 36px 1fr auto;
  gap: 10px; align-items: center;
  border: 1px solid var(--line); background: #fff;
  border-radius: 14px; padding: 10px 12px;
}
.step-no { font-weight: 800; color: var(--muted); }
.step-side { font-size: 15px; }
.step-out { font-weight: 750; font-size: 14px; text-align: right; }
.step-out.left { color: var(--left); }
.step-out.right { color: var(--right); }
.step-out.both { color: var(--warn); }
.hist {
  width: 100%; text-align: left; border: 1px solid var(--line); background: #fff;
  border-radius: 14px; padding: 12px 14px;
}
.hist .row { display: flex; justify-content: space-between; gap: 8px; }
.hist b { font-size: 16px; }
.hist .dim { color: var(--muted); font-size: 12px; margin-top: 4px; }
.hist-empty { color: var(--muted); font-size: 14px; padding: 12px 4px; }
.sheet-actions { display: grid; gap: 8px; margin-top: 16px; }
.ghost.danger { color: var(--left); }
.debug-box { margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--line); }
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 8px 0; }
.debug-box .switch { color: var(--ink); }
.debug-float {
  position: fixed; right: 12px; bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 12; width: 38vw; max-width: 180px;
  aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow); background: #111;
}

.cal {
  position: fixed; inset: 0; z-index: 22;
  background: #12100e;
  display: flex; flex-direction: column;
  color: #fff8ec;
}
#calibrate.hidden {
  display: flex !important;
  pointer-events: none;
  transform: translate3d(-120%, 0, 0);
}
.cal-head { padding: calc(16px + env(safe-area-inset-top)) 20px 10px; }
.cal-head p { margin: 6px 0 0; color: #cbbba6; font-size: 14px; }
.cal-steps {
  margin: 8px 0 0;
  padding-left: 1.25em;
  color: #cbbba6;
  font-size: 14px;
  line-height: 1.45;
}
.cal-steps li + li { margin-top: 6px; }
.cal-stage {
  position: relative;
  margin: 8px 16px;
  flex: 1;
  border-radius: 22px;
  overflow: hidden;
  background: #000;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
#calCanvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}
#calibrate .guides { display: none; }
.cal-dock {
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
}
.cal-dock .shoot { background: #fff8ec; color: var(--ink); }
.cal-dock .dock-row { margin-top: 10px; }
.ghost.light {
  width: 100%;
  background: transparent; color: #ffe7c2; border-color: #4a4238;
}

@media (max-width: 420px) {
  .seat-score { font-size: 44px; }
  .call-main { font-size: 22px; }
  .fx-banner { font-size: 26px; padding: 12px 20px; }
}
