/* 夜の茶の間：漆の黒・生成りの紙・真鍮・青磁。3D の背景色と揃えた単一テーマ */
:root {
  --night: #17110d;
  --lacquer: rgba(22, 16, 12, .8);
  --lacquer-line: rgba(216, 178, 90, .28);
  --ivory: #f1e8d4;
  --muted: #b3a58c;
  --brass: #d8b25a;
  --seiji: #6fd0bb;
  --shu: #e0643f;
  --ink: #1d1814;
  --f-display: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --f-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --f-dial: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
  color-scheme: dark;
}

[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; overflow-x: clip; }
body {
  background: var(--night);
  color: var(--ivory);
  font-family: var(--f-body);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--seiji); outline-offset: 2px; }

#stage {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* ---- 上部 HUD ---- */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none;
  z-index: 3;
}
.hud-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.hud-time, .hud-money { font-family: var(--f-display); font-weight: 800; font-size: 30px; font-variant-numeric: tabular-nums; text-shadow: 0 2px 10px rgba(0,0,0,.6); }
.hud-time small, .hud-money small { font-size: 14px; margin: 0 2px; color: var(--muted); }
.hud-money { color: var(--brass); white-space: nowrap; }
.hud-course { white-space: nowrap; font-size: 12px; letter-spacing: .12em; color: var(--muted); padding: 2px 10px; border: 1px solid var(--lacquer-line); border-radius: 999px; background: var(--lacquer); }
.bar { height: 4px; border-radius: 4px; background: rgba(241,232,212,.14); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; width: 100%; background: var(--ivory); transform-origin: left; }
.bar.thin { height: 3px; margin-top: 8px; }
.bar.thin i { background: var(--seiji); }
.bar.thin i.low { background: var(--shu); }
.hud-mid { display: flex; align-items: center; gap: 6px; min-width: 0; }
#quitBtn { pointer-events: auto; white-space: nowrap; }
#quitBtn.warn { position: absolute; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 52px); z-index: 4; font-size: 13px; padding: 6px 14px; }
.ghost-btn { background: var(--lacquer); border: 1px solid var(--lacquer-line); border-radius: 999px; padding: 4px 12px; font-size: 12px; color: var(--muted); }
.ghost-btn.warn { color: var(--ivory); background: var(--shu); border-color: var(--shu); }

/* ---- 注文票 ---- */
#order {
  position: fixed; left: 50%; top: 0;
  transform: translate(-50%, 0);
  width: min(360px, calc(100vw - 32px));
  padding: 10px 16px 12px;
  background: linear-gradient(180deg, rgba(241,232,212,.97), rgba(228,215,188,.97));
  color: var(--ink);
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.4);
  z-index: 2;
  pointer-events: none;
}
#order::before { /* 伝票の上の綴じ穴 */
  content: ""; position: absolute; left: 12px; right: 12px; top: 4px; height: 3px;
  background: radial-gradient(circle, rgba(29,24,20,.25) 1.2px, transparent 1.6px) 0 0 / 10px 3px repeat-x;
}
.order-head { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.chip { font-size: 11px; letter-spacing: .1em; padding: 2px 8px; border-radius: 3px; background: #7a6a58; color: #f7f3ea; font-weight: 700; }
.who { font-size: 12px; color: #6d5d4b; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trouble { margin: 4px 0 0; font-family: var(--f-display); font-weight: 800; font-size: 17px; line-height: 1.35; text-wrap: balance; }
.to { margin: 0; text-align: right; font-size: 12px; color: #6d5d4b; min-height: 1.4em; }
.to b { color: var(--ink); }
/* 緊急のメモ */
#order.emergency { background: linear-gradient(180deg, #fff1e6, #f6dccb); box-shadow: 0 10px 30px rgba(0,0,0,.45), 0 0 0 3px var(--shu), 0 0 34px rgba(224,100,63,.55); }
#order.emergency .chip { background: var(--shu); animation: blink .6s steps(2) infinite; }
#order.emergency .trouble { color: #8f2414; }
@keyframes blink { 50% { opacity: .45; } }
.digits span.mask:not(.done) { color: transparent; }
.digits span.mask::before { content: ""; position: absolute; left: 8%; right: 8%; top: 14%; bottom: 10%; border-radius: 6px; background: repeating-linear-gradient(135deg, rgba(143,36,20,.18) 0 5px, rgba(143,36,20,.08) 5px 10px); box-shadow: inset 0 0 0 2px rgba(143,36,20,.35); }
.digits span.mask.done { color: rgba(143,36,20,.85); }
.digits span.mask.done::before { display: none; }
.digits span.mask.now::before { box-shadow: inset 0 0 0 2px var(--shu); }
/* 知らせ */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  width: min(340px, calc(100vw - 48px));
  display: grid; gap: 2px; text-align: center;
  padding: 10px 14px; border-radius: 10px;
  background: rgba(20,15,12,.92); border: 1px solid var(--lacquer-line);
  z-index: 5; pointer-events: none;
  animation: toastIn .25s ease-out;
}
.toast b { font-family: var(--f-display); font-size: 18px; color: var(--brass); }
.toast span { font-size: 12px; color: var(--ivory); line-height: 1.5; }
.toast.bad b { color: var(--shu); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }
.digits {
  display: flex; justify-content: center; align-items: center; gap: 2px;
  font-family: var(--f-display); font-weight: 800;
  font-size: clamp(34px, 11vw, 48px); line-height: 1.15;
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
  margin-top: 2px;
}
.digits span { width: .66em; text-align: center; color: #3b322a; transition: color .12s; position: relative; }
.digits span.done { color: rgba(29,24,20,.22); }
.digits span.now { color: var(--ink); }
.digits span.now::after { content: ""; position: absolute; left: 12%; right: 12%; bottom: .02em; height: 3px; border-radius: 2px; background: var(--shu); }
.digits .sep { width: .35em; color: rgba(29,24,20,.35); }
.digits.practice span { color: var(--ink); }
.digits.practice .empty { font-size: 15px; font-family: var(--f-body); font-weight: 400; color: #7a6a58; width: auto; }
#order.shake { animation: shake .28s; }
@keyframes shake { 20% { transform: translate(calc(-50% - 7px), 0); } 40% { transform: translate(calc(-50% + 6px), 0); } 60% { transform: translate(calc(-50% - 4px), 0); } 80% { transform: translate(calc(-50% + 2px), 0); } }
#order.pop { animation: pop .3s; }
@keyframes pop { 40% { transform: translate(-50%, 0) scale(1.04); } }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--f-display); font-weight: 800; font-size: 54px; color: var(--shu);
  background: rgba(241,232,212,.94); border-radius: 6px;
}

/* ---- ホーム ---- */
.panel {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  z-index: 3;
  pointer-events: none;
}
.panel > * { pointer-events: auto; }
.logo {
  margin: 0; font-family: var(--f-display); font-weight: 800;
  line-height: 1;
  text-shadow: 0 3px 0 #000, 0 0 24px rgba(216,178,90,.25);
  font-size: clamp(34px, 11vw, 54px); letter-spacing: .04em; text-wrap: balance; text-align: center;
}
.logo span { color: var(--brass); }
.lead { margin: 0; font-size: 13px; color: var(--muted); padding: 3px 12px; border-radius: 999px; background: var(--lacquer); }
.courses { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: min(420px, 100%); margin-top: 4px; }
.course {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 9px;
  background: var(--lacquer); border: 1px solid var(--lacquer-line); border-radius: 10px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: transform .12s, border-color .12s;
}
.course:active { transform: scale(.97); }
.course:hover { border-color: var(--brass); }
.course .c-name { font-family: var(--f-display); font-weight: 800; font-size: 17px; }
.course .c-price { color: var(--brass); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.course .c-sec { font-size: 11px; color: var(--muted); }
.course .c-mask { font-size: 10px; color: var(--ivory); opacity: .8; }
.course .c-best { font-size: 10px; color: var(--seiji); min-height: 1.3em; font-variant-numeric: tabular-nums; }
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.links button, .links a { background: var(--lacquer); border: 1px solid transparent; border-radius: 999px; padding: 4px 9px; font-size: 12px; color: var(--ivory); text-decoration: none; }
.links a.support { border-color: var(--brass); color: var(--brass); }
.res-support { margin: 14px 0 0; text-align: center; font-size: 13px; }
.res-support a { color: var(--brass); }
.try-hint {
  position: fixed; left: 0; right: 0; margin: 0; text-align: center;
  font-size: 12px; color: var(--muted); pointer-events: none; z-index: 2;
  text-shadow: 0 1px 4px #000;
}

/* ---- シート ---- */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(10, 7, 5, .55);
  padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
}
.sheet-body {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100% - env(safe-area-inset-top, 0px) - 40px);
  overflow: auto;
  background: #211812;
  border: 1px solid var(--lacquer-line); border-bottom: 0;
  border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  animation: rise .28s cubic-bezier(.2,.8,.2,1);
  -webkit-user-select: text; user-select: text;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { font-family: var(--f-display); font-weight: 800; font-size: 22px; margin: 0 0 12px; text-wrap: balance; }
.sheet h3 { font-size: 14px; margin: 14px 0 6px; color: var(--brass); }
.sheet h3 time { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 12px; }
.sheet ul, .sheet ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; line-height: 1.6; }
.note { font-size: 12px; color: var(--muted); line-height: 1.6; }
.close { position: absolute; right: 12px; top: 10px; width: 36px; height: 36px; border: 0; background: transparent; font-size: 22px; color: var(--muted); }
.price { border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; font-size: 13px; }
.price th, .price td { padding: 4px 7px; border-bottom: 1px solid rgba(241,232,212,.12); text-align: center; }
.price th { color: var(--shu); font-family: var(--f-display); font-size: 16px; text-align: left; }
.price td { text-align: left; }
.setting { margin-bottom: 16px; }
.setting-name { margin: 0 0 6px; font-weight: 700; }
.seg { display: inline-flex; border: 1px solid var(--lacquer-line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 16px; font-size: 13px; color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--brass); color: var(--ink); font-weight: 700; }

/* 結果 */
.res-course { margin: 0; font-size: 12px; letter-spacing: .1em; color: var(--muted); }
.res-verdict { margin: 4px 0 0; font-family: var(--f-display); font-weight: 800; font-size: 32px; line-height: 1.2; }
.res-verdict.win { color: var(--brass); }
.res-verdict.lose { color: var(--ivory); }
.res-total { margin: 4px 0 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.res-total small { color: var(--muted); }
.res-total span { font-family: var(--f-display); font-weight: 800; font-size: 20px; }
.res-stats { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin: 0 0 12px; }
.res-stats div { background: rgba(241,232,212,.06); border-radius: 8px; padding: 8px 10px; }
.res-stats dt { font-size: 11px; color: var(--muted); }
.res-stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.res-learn { display: grid; gap: 6px; margin-bottom: 16px; }
.res-learn:empty { display: none; }
.res-learn h3 { margin: 0 0 2px; font-size: 13px; color: var(--muted); font-weight: 400; }
.res-learn div { display: grid; grid-template-columns: 3.2em 1fr; gap: 10px; align-items: baseline; padding: 6px 10px; border-radius: 8px; background: rgba(241,232,212,.06); }
.res-learn div b { font-family: var(--f-display); font-size: 20px; color: var(--shu); font-variant-numeric: tabular-nums; }
.res-learn div span { font-size: 12px; line-height: 1.5; min-width: 0; }
.res-actions { display: flex; gap: 10px; }
.share-btn { display: block; text-align: center; margin: 0 0 10px; padding: 12px; border-radius: 12px; background: #f1e8d4; color: var(--ink); font-weight: 700; text-decoration: none; }
.share-btn:active { transform: scale(.98); }
.main-btn, .sub-btn { flex: 1; padding: 13px; border-radius: 12px; font-weight: 700; font-size: 15px; }
.main-btn { background: var(--brass); color: var(--ink); border: 0; }
.sub-btn { background: transparent; border: 1px solid var(--lacquer-line); }

.loading {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 20;
  background: var(--night); color: var(--muted); font-size: 13px; transition: opacity .4s;
}
.loading.gone { opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ホームの試し回し欄は小さく */
#order.compact .trouble, #order.compact .to, #order.compact .bar { display: none; }
#order.compact .digits { font-size: clamp(28px, 9vw, 40px); }
