/* Yokochō — UI over the 3D canvas. Night-alley palette: navy sky, lantern red,
   amber, washi paper. Japanese text uses the device's own Japanese fonts (no
   web-font download — Hiragino on Apple, Noto CJK on Android, Yu Gothic on
   Windows). Phone rules: choices ≥ 48 px, furigana ≥ 11 px. */
:root {
  color-scheme: dark;   /* a deliberately single-theme night scene */
  --navy: #0b1024; --wood: #17110d; --wood2: #241a13; --red: #d8432a; --amber: #e8a33a;
  --paper: #f4ede0; --ink: #1a120c; --muted: #c9b79c; --green: #8fe0a0; --dim: rgba(244,237,224,0.6);
  /* Latin first (so romaji macrons render), then explicit Japanese faces so kanji
     never fall back to a Chinese font */
  --jp: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", "Meiryo", sans-serif;
  --pix: "Press Start 2P", ui-monospace, monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: var(--navy); color: var(--paper);
  font-family: var(--jp); -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
#scene { position: fixed; inset: 0; display: block; }
.hidden { display: none !important; }

/* ruby / romaji / English visibility */
ruby { ruby-position: over; }
rt { font-size: 0.55em; color: var(--muted); font-weight: 700; letter-spacing: 0; }
body.no-furi rt { visibility: hidden; }
body.no-ro #dlg-ro, body.no-ro .c-ro, body.no-ro .c-react-ro { display: none; }
#dlg-en, .c-en { display: none; }
body.show-en #dlg-en, body.show-en .c-en, .choice.sel .c-en { display: block; }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 60; transition: opacity 0.36s ease; }
#fade.on { opacity: 1; }

/* ---------- title ---------- */
#title { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 35%, rgba(11,16,36,0.25), rgba(11,16,36,0.82)); overflow-y: auto; }
.t-card { width: min(560px, 100%); text-align: center; padding: 26px 18px 18px; border-radius: 18px;
  background: rgba(23,17,13,0.86); border: 2px solid rgba(216,67,42,0.7); box-shadow: 0 10px 40px rgba(0,0,0,0.5); }
.t-kanji { font-size: clamp(58px, 15vw, 92px); font-weight: 900; color: var(--paper); line-height: 1;
  text-shadow: 0 0 22px rgba(232,163,58,0.55), 0 4px 0 #6a1a10; font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; }
.t-name { font-family: var(--pix); font-size: 15px; letter-spacing: 6px; color: var(--amber); margin-top: 10px; }
.t-sub { font-size: 16px; line-height: 1.5; color: var(--paper); margin: 14px auto 0; max-width: 430px; }
.t-label { font-family: var(--pix); font-size: 9px; letter-spacing: 2px; color: var(--muted); margin-top: 20px; }
.t-levels { display: flex; gap: 8px; margin-top: 8px; }
.lv { flex: 1; min-height: 52px; border-radius: 12px; background: var(--wood2); border: 2px solid rgba(232,163,58,0.25); padding: 8px 4px; }
.lv b { display: block; font-size: 14px; } .lv small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.lv.on { border-color: var(--amber); background: #3a2414; }
.t-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.t-buttons button { min-height: 56px; font-size: 18px; font-weight: 800; border-radius: 14px; border: none;
  background: var(--red); color: #fff; box-shadow: 0 4px 0 #7a1e12; }
.t-buttons button + button { background: #2a3a5a; box-shadow: 0 4px 0 #141d33; }
.t-buttons small { font-family: var(--pix); font-size: 9px; opacity: 0.8; margin-left: 6px; }
.t-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin-top: 16px; font-size: 14px; }
.t-links a, .t-links button { color: var(--amber); background: none; border: none; text-decoration: none; font-weight: 700; padding: 6px 2px; }
.t-beta { font-size: 11px; color: var(--muted); margin-top: 14px; line-height: 1.4; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-btn { pointer-events: auto; min-width: 44px; height: 44px; padding: 0 12px; font-size: 15px; font-weight: 800;
  background: rgba(23,17,13,0.82); color: var(--paper); border: 2px solid rgba(232,163,58,0.45); border-radius: 12px; }
#btn-book { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; }
.hud-right { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }
#btn-map { font-family: var(--pix); font-size: 10px; }
#hud-hint { position: absolute; bottom: max(12px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 13px; font-weight: 700; color: rgba(244,237,224,0.9); background: rgba(0,0,0,0.38); padding: 6px 14px;
  border-radius: 999px; white-space: nowrap; }
@media (pointer: coarse) { #hud-hint { display: none; } }
#toast { position: fixed; top: max(66px, calc(env(safe-area-inset-top) + 54px)); left: 50%; transform: translate(-50%, -8px);
  z-index: 15; opacity: 0; transition: opacity 0.4s, transform 0.4s; pointer-events: none;
  font-weight: 800; font-size: 15px; background: rgba(23,17,13,0.88); border: 2px solid var(--amber); color: var(--paper);
  padding: 9px 16px; border-radius: 12px; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#prompt { position: fixed; left: 50%; bottom: 20%; transform: translateX(-50%); z-index: 11; text-align: center;
  background: rgba(23,17,13,0.9); border: 2px solid var(--red); border-radius: 14px; padding: 10px 18px; animation: bob 1.2s ease-in-out infinite; }
#prompt-name { font-size: 20px; font-weight: 900; } #prompt-name small { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
.p-key { font-family: var(--pix); font-size: 10px; margin-top: 6px; color: var(--amber); } .p-key b { color: var(--green); }
@media (pointer: coarse) { .p-key { display: none; } #prompt { bottom: auto; top: 22%; } }
#enter-btn { position: fixed; right: 18px; bottom: max(30px, calc(env(safe-area-inset-bottom) + 18px)); z-index: 12;
  width: 96px; height: 96px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.5); background: var(--red); color: #fff;
  font-size: 26px; font-weight: 900; line-height: 1; box-shadow: 0 4px 0 #7a1e12; animation: bob 1.2s ease-in-out infinite; }
#enter-btn small { display: block; font-family: var(--pix); font-size: 8px; margin-top: 6px; }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -5px; } }
#joystick { position: fixed; left: 22px; bottom: max(26px, calc(env(safe-area-inset-bottom) + 14px)); width: 128px; height: 128px;
  border-radius: 50%; background: rgba(255,255,255,0.1); border: 2px solid rgba(255,255,255,0.32); z-index: 12; touch-action: none; }
#stick { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; transform: translate(-50%, -50%);
  border-radius: 50%; background: rgba(255,255,255,0.55); }

/* ---------- dialogue ---------- */
#dialogue { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#meter { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(90vw, 520px); }
#meter-bar { position: relative; height: 12px; border-radius: 6px; border: 2px solid rgba(0,0,0,0.45);
  background: linear-gradient(90deg, #5a6a9a, #e8a33a 60%, #8fe0a0); box-shadow: 0 2px 6px rgba(0,0,0,0.4); }
#meter-marker { position: absolute; top: -15px; left: 30%; transform: translateX(-50%); font-size: 16px; color: #fff;
  text-shadow: 0 2px 2px rgba(0,0,0,0.7); transition: left 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
#meter-labels { display: flex; justify-content: space-between; margin-top: 3px; font-size: 11px; font-weight: 800;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9); }
#meter-labels span:first-child { color: #b8c8ff; } #meter-labels span:last-child { color: var(--green); }
#meter-tier { color: var(--paper); }

#dlg-panel { pointer-events: auto; position: absolute; left: 0; right: 0; bottom: 0; max-height: 60vh; overflow-y: auto;
  background: linear-gradient(180deg, rgba(23,17,13,0.97), rgba(16,12,9,0.99)); border-top: 3px solid var(--red);
  padding: 10px 14px calc(max(12px, env(safe-area-inset-bottom)) + 6px); -webkit-overflow-scrolling: touch; }
@media (min-width: 900px) { #dlg-panel { left: 50%; right: auto; width: 760px; transform: translateX(-50%); border-radius: 16px 16px 0 0;
  border: 3px solid var(--red); border-bottom: none; } }
#dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#dlg-speaker { font-size: 17px; font-weight: 900; color: var(--amber); } #dlg-speaker small { font-size: 12px; color: var(--muted); font-weight: 700; margin-left: 4px; }
#dlg-speaker .narr { color: var(--muted); letter-spacing: 4px; }
#dlg-tools { display: flex; gap: 6px; flex-shrink: 0; }
#dlg-tools button { min-width: 38px; height: 34px; padding: 0 7px; font-size: 13px; font-weight: 900; border-radius: 9px;
  background: var(--wood2); border: 1px solid rgba(232,163,58,0.35); color: var(--dim); }
#dlg-tools button.on { color: var(--green); border-color: rgba(143,224,160,0.6); }
#dlg-to { font-size: 13px; color: var(--muted); margin-top: 2px; } #dlg-to b { color: var(--paper); } #dlg-to small { color: var(--muted); }
#dlg-line { font-size: 22px; font-weight: 800; line-height: 1.75; margin-top: 6px; color: #fff4e0; }
#dlg-line.narration { font-size: 16px; font-weight: 600; line-height: 1.5; font-style: italic; color: var(--paper); }
#dlg-line .sign { font-style: normal; font-weight: 900; font-size: 20px; color: var(--amber); }
#dlg-ro { font-size: 14px; color: var(--muted); margin-top: 2px; font-weight: 600; }
#dlg-en { font-size: 14px; color: #e8c88a; font-style: italic; margin-top: 2px; }
#dlg-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.choice { position: relative; text-align: left; min-height: 52px; padding: 8px 12px 8px 40px; border-radius: 12px;
  background: var(--wood2); border: 2px solid rgba(232,163,58,0.3); }
.choice .num { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; border-radius: 50%;
  background: rgba(232,163,58,0.2); font-size: 12px; font-weight: 900; display: flex; align-items: center; justify-content: center; color: var(--amber); }
.choice .c-ja { display: block; font-size: 20px; font-weight: 800; line-height: 1.7; color: #fff4e0; }
.choice .c-act { display: block; font-size: 15px; font-weight: 700; color: var(--amber); }
.choice .c-ro { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.choice .c-en { font-size: 13px; color: #e8c88a; font-style: italic; margin-top: 2px; }
.choice.sel { border-color: var(--amber); background: #3a2414; box-shadow: 0 0 0 2px rgba(232,163,58,0.35); }
@media (hover: hover) { .choice:hover { border-color: rgba(232,163,58,0.8); } }
#dlg-commit { position: sticky; bottom: 0; width: 100%; min-height: 54px; margin-top: 10px; font-size: 18px; font-weight: 900;
  border: none; border-radius: 14px; background: var(--red); color: #fff; box-shadow: 0 4px 0 #7a1e12; }

/* ---------- card ---------- */
#card { position: fixed; inset: 0; z-index: 30; background: rgba(5,5,10,0.78); display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto; }
#card-inner { width: min(620px, 100%); max-height: 100%; text-align: center; padding: 18px 16px; border-radius: 18px;
  background: rgba(23,17,13,0.96); border: 2px solid rgba(232,163,58,0.5); margin: auto; }
.c-title { font-size: 22px; font-weight: 900; color: var(--amber); }
.c-title-ja { font-size: 26px; font-weight: 900; margin-top: 4px; line-height: 1.8; }
.c-body { font-size: 16px; line-height: 1.55; margin-top: 12px; color: var(--paper); text-align: left; }
.c-react { font-size: 21px; font-weight: 800; line-height: 1.75; color: #fff4e0; }
.c-react .who { display: block; font-size: 13px; color: var(--amber); font-weight: 900; line-height: 1.4; }
.c-react-ro { font-size: 13px; color: var(--muted); } .c-react-en { font-size: 14px; color: #e8c88a; font-style: italic; margin-top: 4px; }
.c-react-act { font-size: 16px; font-style: italic; color: var(--paper); margin-bottom: 4px; }
.c-react-act.after { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
.c-verdict { font-size: 17px; font-weight: 900; margin-top: 14px; }
.c-verdict .reg { display: inline-block; font-size: 12px; font-weight: 800; color: var(--paper); background: #2a3a5a;
  border-radius: 999px; padding: 3px 10px; margin-left: 6px; vertical-align: middle; }
.c-tip { font-size: 16px; line-height: 1.55; margin-top: 10px; text-align: left; color: var(--paper); }
.c-phrase { margin-top: 12px; font-size: 16px; font-weight: 800; color: #ffe27a; background: #3a2214; border-radius: 10px; padding: 8px 12px; line-height: 1.7; }
.c-phrase small { color: var(--muted); font-weight: 600; }
.c-tier { font-size: 40px; font-weight: 900; margin-top: 4px; }
.c-tier-ro { font-family: var(--pix); font-size: 10px; color: var(--muted); margin-top: 6px; letter-spacing: 1px; }
.c-stats { font-size: 13px; color: var(--muted); margin-top: 10px; }
.c-phrases { margin-top: 12px; text-align: left; font-size: 15px; line-height: 1.8; background: #241a13; border-radius: 12px; padding: 10px 12px; }
.c-phrases small { color: var(--muted); }
.c-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.c-btns button { min-height: 52px; font-size: 16px; font-weight: 900; border: none; border-radius: 14px; background: #2e8a5a; color: #fff; box-shadow: 0 4px 0 #1a5a3a; }
.c-btns button.retry { background: var(--red); box-shadow: 0 4px 0 #7a1e12; }
.c-btns button.ghost { background: transparent; border: 2px solid rgba(232,163,58,0.5); box-shadow: none; color: var(--amber); }

/* ---------- shop list / phrase book ---------- */
#shops, #book { position: fixed; inset: 0; z-index: 45; background: rgba(5,5,10,0.8); display: flex; justify-content: center; padding: 16px; overflow-y: auto; }
.sh-wrap, .bk-wrap { width: min(620px, 100%); margin: auto 0; background: rgba(23,17,13,0.97); border: 2px solid var(--red); border-radius: 18px; padding: 14px; }
.sh-head, .bk-head { display: flex; justify-content: space-between; align-items: center; font-family: var(--pix); font-size: 11px; color: var(--amber); }
.sh-head button, .bk-head button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(232,163,58,0.4); background: var(--wood2); font-size: 16px; }
#shops-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.shop-card { display: flex; align-items: center; gap: 12px; text-align: left; min-height: 74px; padding: 10px 12px; border-radius: 14px;
  background: var(--wood2); border: 2px solid rgba(232,163,58,0.3); }
.s-icon { font-size: 34px; } .s-main { flex: 1; min-width: 0; }
.s-ja { display: block; font-size: 19px; font-weight: 900; line-height: 1.7; }
.s-en { display: block; font-size: 13px; font-weight: 800; color: var(--amber); }
.s-desc { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.s-badge { font-size: 13px; font-weight: 900; color: var(--green); text-align: right; white-space: nowrap; }
.s-badge small { display: block; color: var(--muted); font-size: 11px; }
.bk-tabs { display: flex; gap: 8px; margin-top: 12px; }
.bk-tabs button { flex: 1; min-height: 42px; border-radius: 10px; border: 2px solid rgba(232,163,58,0.3); background: var(--wood2); font-weight: 800; }
.bk-tabs button.on { border-color: var(--amber); background: #3a2414; }
#book-head { font-size: 13px; color: var(--muted); margin: 10px 0 6px; }
#book-list { display: flex; flex-direction: column; gap: 6px; }
.ph { position: relative; padding: 8px 10px 8px 52px; border-radius: 10px; background: #1d1510; min-height: 52px; }
.ph.locked { padding-left: 12px; opacity: 0.55; }
.ph-say { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 9px; border: none; background: var(--wood2); }
.ph-ja { display: block; font-size: 18px; font-weight: 800; line-height: 1.7; }
.ph-ro { display: block; font-size: 13px; color: var(--muted); } .ph-en { display: block; font-size: 13px; color: #e8c88a; }
.ph-ok { position: absolute; right: 10px; top: 8px; font-size: 11px; color: var(--green); font-weight: 800; }
#book-quiz { margin-top: 12px; }
#quiz-prompt { font-size: 17px; line-height: 1.5; } #quiz-prompt b { color: var(--amber); }
#quiz-input { width: 100%; min-height: 50px; margin-top: 10px; font-size: 18px; padding: 10px 12px; border-radius: 12px;
  border: 2px solid rgba(232,163,58,0.5); background: #0f0b08; color: var(--paper); font-family: var(--jp); }
.quiz-btns { display: flex; gap: 8px; margin-top: 10px; }
.quiz-btns button { flex: 1; min-height: 48px; border-radius: 12px; border: none; background: #2e8a5a; color: #fff; font-weight: 900; font-size: 16px; }
#quiz-say { flex: 0 0 60px; background: var(--wood2); }
#quiz-result { margin-top: 12px; text-align: center; }
.qr-ok { color: var(--green); font-weight: 900; } .qr-no { color: #ff9a8a; font-weight: 900; }
.qr-ja { font-size: 22px; font-weight: 900; line-height: 1.8; margin-top: 6px; } .qr-ro { color: var(--muted); }

#voice-warn { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 50;
  background: #3a2214; border: 2px solid var(--amber); border-radius: 14px; padding: 12px 14px; font-size: 14px; line-height: 1.45; }
#voice-warn button { display: block; margin-top: 8px; min-height: 40px; padding: 0 18px; border-radius: 10px; border: none; background: var(--amber); color: var(--ink); font-weight: 900; }

#loading { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--navy); color: var(--paper); font-size: 26px; font-weight: 900; transition: opacity 0.5s ease; }
#loading small { font-family: var(--pix); font-size: 9px; color: var(--amber); letter-spacing: 2px; }
#loading.hidden { opacity: 0; pointer-events: none; display: flex !important; }

/* ---------- small phones: everything fits without scrolling past choice 4 ---------- */
@media (max-width: 520px) {
  #meter { top: calc(max(10px, env(safe-area-inset-top)) + 54px); width: calc(100vw - 32px); }
  #meter-labels { font-size: 10px; }
  #dlg-panel { max-height: 70vh; padding: 8px 10px calc(max(10px, env(safe-area-inset-bottom)) + 4px); }
  #dlg-speaker { font-size: 15px; }
  #dlg-tools { gap: 4px; }
  #dlg-tools button { min-width: 32px; height: 30px; padding: 0 5px; font-size: 12px; }
  #dlg-to { font-size: 12px; }
  #dlg-line { font-size: 18px; line-height: 1.65; margin-top: 2px; }
  #dlg-line.narration { font-size: 15px; }
  #dlg-ro, #dlg-en { font-size: 12.5px; }
  #dlg-choices { gap: 6px; margin-top: 7px; }
  .choice { min-height: 48px; padding: 5px 10px 5px 34px; border-radius: 10px; }
  .choice .num { left: 8px; width: 20px; height: 20px; font-size: 11px; }
  .choice .c-ja { font-size: 16.5px; line-height: 1.6; }
  .choice .c-act { font-size: 14px; }
  .choice .c-ro, .choice .c-en { font-size: 12px; }
  #dlg-commit { min-height: 50px; margin-top: 8px; font-size: 17px; }
  rt { font-size: 0.62em; }          /* keeps furigana ≥ 10–11px at the smaller base size */
}
