/* Japan Culture Quiz - prototype styles (v05 lineage) */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
  color: #fdfdf8; min-height: 100vh; overflow-x: hidden;
  background: #1d2733;
}
#bg-video {
  position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2;
}
#bg-shade {
  position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, rgba(16,24,36,.42), rgba(16,24,36,.62) 55%, rgba(16,24,36,.78));
}
.topbar {
  position: fixed; top: 10px; right: 10px; z-index: 30; display: flex; gap: 8px;
}
.chip-btn {
  border: 1px solid rgba(255,255,255,.35); background: rgba(20,30,44,.72); color: #fff;
  border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer; backdrop-filter: blur(4px);
}
.audio-panel {
  position: fixed; top: 52px; right: 10px; z-index: 30; display: flex; gap: 16px;
  background: rgba(20,30,44,.88); border: 1px solid rgba(255,255,255,.25); border-radius: 12px;
  padding: 10px 14px; backdrop-filter: blur(4px);
}
.audio-panel[hidden] { display: none; }
.audio-panel label { color: #fff; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.audio-panel input[type="range"] { width: 104px; accent-color: #f2784b; }
.roll-hint { font-size: 19px; font-weight: 700; margin: 8px 0 2px; animation: rollpulse 0.9s ease-in-out infinite; }
@keyframes rollpulse { 0%,100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.06); opacity: 1; } }
.wrap { max-width: 560px; margin: 0 auto; padding: 54px 14px 40px; }
.screen { animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.logo-block { text-align: center; margin: 8px 0 14px; text-shadow: 0 2px 14px rgba(0,0,0,.55); }
.logo-kicker { letter-spacing: .14em; font-size: 12px; margin: 0 0 6px; opacity: .9; text-transform: uppercase; }
.logo-kicker.light { color: #ffd98a; }
.logo { font-size: 44px; line-height: 1.08; margin: 0; font-weight: 900; }
.logo-sub { margin: 10px auto 0; max-width: 420px; font-size: 15px; line-height: 1.5; }

.title-row { display: flex; gap: 12px; align-items: center; margin: 10px 0 14px; }
.center-row { justify-content: center; }
.pico-slot { flex: 0 0 auto; width: 92px; height: 92px; }
.pico-slot.big { width: 118px; height: 118px; }
.pico-slot.stage-pico { width: 84px; height: 84px; }
.kitten-img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(0,0,0,.4)); }
.pico-slot.happy .kitten-img { animation: jump .55s ease; }
.pico-slot.oops .kitten-img { animation: shake .5s ease; }
@keyframes jump { 0% { transform: translateY(0); } 35% { transform: translateY(-16px) rotate(-3deg); } 70% { transform: translateY(2px); } 100% { transform: none; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-7px) rotate(-2deg); } 60% { transform: translateX(6px) rotate(2deg); } }
.bubble {
  position: relative; border-radius: 14px; padding: 10px 14px; font-size: 14px; line-height: 1.55; flex: 1;
}
.bubble.dark, .panel.dark { background: rgba(18,28,42,.82); backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.14); }
.bubble::before {
  content: ""; position: absolute; left: -8px; top: 34px; border: 8px solid transparent;
  border-right-color: rgba(18,28,42,.82); border-left: 0;
}
.panel { border-radius: 18px; padding: 18px 16px; }
.panel.slim { padding: 12px 14px; }
.panel-title { margin: 0 0 12px; font-size: 17px; }
.note { font-size: 12.5px; line-height: 1.6; margin: 12px 0 0; }
.note.dim { opacity: .75; }

.lives-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.lives-label { font-weight: 700; font-size: 14px; }
.lives-note { margin: 0; }
.seg { display: inline-flex; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.22); border-radius: 999px; padding: 3px; gap: 3px; }
.seg button {
  border: 0; background: transparent; color: #fff; font-weight: 700; font-size: 14px;
  padding: 5px 15px; border-radius: 999px; cursor: pointer; line-height: 1.2;
}
.seg button.on { background: linear-gradient(135deg, #ff9a3d, #f2784b); }
.seg button:disabled { cursor: default; opacity: .55; }

.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.cat-btn {
  border: 2px solid rgba(255,255,255,.18); border-radius: 14px; padding: 12px 10px; cursor: pointer;
  color: #fff; text-align: left; font-size: 15px; font-weight: 700; line-height: 1.35;
  background: linear-gradient(135deg, var(--catc), rgba(20,30,44,.55));
  transition: transform .12s ease, border-color .12s ease;
}
.cat-btn:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.55); }
.cat-btn .cat-ja { display: block; font-size: 12px; font-weight: 400; opacity: .85; margin-top: 2px; }
.cat-btn .badge { display: inline-block; margin-top: 6px; font-size: 11.5px; font-weight: 700; background: rgba(0,0,0,.35); border-radius: 999px; padding: 2px 8px; }
.cat-btn .badge.done { background: #ffd23e; color: #4a3800; }

.btn {
  border: 0; border-radius: 999px; padding: 11px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn.primary { background: linear-gradient(135deg, #ff9a3d, #f2784b); color: #fff; box-shadow: 0 4px 14px rgba(242,120,75,.45); width: 100%; }
.btn.big { font-size: 16.5px; padding: 13px 20px; }
.btn.ghost-light { background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.3); }
.btn.small { font-size: 13px; padding: 8px 14px; margin-top: 12px; }
.row { display: flex; gap: 10px; }
.row.col { flex-direction: column; margin-top: 14px; }

.hud-row { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 700; padding: 2px 0; }
.lives { letter-spacing: 2px; font-size: 16px; }
.streak { color: #ffb340; }
.progress { height: 8px; border-radius: 99px; background: rgba(255,255,255,.15); margin-top: 8px; overflow: hidden; }
#progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #ffd23e, #f2784b); border-radius: 99px; transition: width .4s ease; }

.stage-row { display: flex; gap: 12px; align-items: center; margin: 14px 0 10px; }
.dialogue { margin-top: 4px; }
.chips { margin: 0 0 8px; }
.chip { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 10px; background: var(--catc, #3f7cac); color: #fff; }
.chip.diff { background: rgba(255,255,255,.16); }
.art-panel {
  border-radius: 14px; overflow: hidden; margin: 6px 0 12px; line-height: 0;
  background: linear-gradient(135deg, var(--catc, #3f7cac), rgba(20,30,44,.35));
  border: 1px solid rgba(255,255,255,.18);
}
.art-panel svg { width: 100%; height: auto; display: block; }
.art-panel img.qimg { width: 100%; height: auto; display: block; max-height: 300px; object-fit: contain; background: #f6f1e5; }
#prompt { font-size: 20px; line-height: 1.45; margin: 4px 0 14px; }
#choices { display: grid; gap: 10px; }
.choice {
  text-align: left; border: 2px solid rgba(255,255,255,.2); background: rgba(255,255,255,.07); color: #fff;
  border-radius: 13px; padding: 12px 14px; font-size: 16px; cursor: pointer; line-height: 1.4;
  transition: border-color .12s, background .12s, transform .12s;
}
.choice:hover:not(:disabled) { border-color: #ffd23e; transform: translateY(-1px); }
.choice:disabled { cursor: default; opacity: .92; }
.choice.correct { background: rgba(80,180,90,.35); border-color: #6fdc73; }
.choice.wrong { background: rgba(220,70,60,.32); border-color: #ff7a6b; }
#feedback { margin-top: 14px; border-top: 1px dashed rgba(255,255,255,.25); padding-top: 12px; }
#feedback-title { font-size: 17px; font-weight: 800; margin: 0 0 6px; }
#feedback-title.good { color: #8df090; }
#feedback-title.bad { color: #ff9a8a; }
#feedback-fact { font-size: 14.5px; line-height: 1.6; margin: 0 0 12px; background: rgba(255,217,138,.12); border-left: 4px solid #ffd98a; padding: 8px 12px; border-radius: 0 10px 10px 0; }

.center { text-align: center; }
#result-heading { font-size: 27px; margin: 6px 0 10px; }
.rank { font-size: 54px; font-weight: 900; margin: 4px 0; color: #ffd23e; text-shadow: 0 3px 16px rgba(255,210,62,.4); }
.result-score { font-size: 19px; font-weight: 800; margin: 4px 0; }
#result-message { font-size: 14.5px; line-height: 1.6; opacity: .92; }
.review { text-align: left; margin: 14px 0 4px; display: grid; gap: 8px; max-height: 300px; overflow: auto; padding-right: 2px; }
.review-item { font-size: 13.5px; line-height: 1.5; background: rgba(255,255,255,.06); border-radius: 10px; padding: 8px 11px; border-left: 4px solid #6fdc73; }
.review-item.miss { border-left-color: #ff7a6b; }
.review-item .rq { font-weight: 700; display: block; }
.review-item .ra { opacity: .9; }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.confetti-piece { position: absolute; top: -14px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(560deg); } }

@media (max-width: 480px) {
  .logo { font-size: 36px; }
  #prompt { font-size: 18px; }
  .cat-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- one-screen quiz layout ----------
   The quiz screen must fit the viewport without page scrolling, so the
   Next button is always reachable (real-device feedback: scrolling to
   Next on every question was stressful, on phones and PC alike).
   On height-constrained screens the quiz becomes a flex column of
   exactly the available height; the art panel is the only flexible
   element and shrinks first, and the feedback fact scrolls inside its
   own box as a last resort. Tall displays keep the original flow. */
@media (max-height: 1100px) {
  #screen-quiz:not([hidden]) {
    display: flex; flex-direction: column;
    height: calc(100vh - 94px); height: calc(100dvh - 94px);
  }
  #screen-quiz .hud { flex: 0 0 auto; }
  #screen-quiz .stage-row { flex: 0 0 auto; }
  #screen-quiz .dialogue { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  #screen-quiz .chips { flex: 0 0 auto; }
  #screen-quiz .art-panel {
    flex: 1 1 auto; min-height: 72px; max-height: 300px; display: flex; margin: 4px 0 10px;
  }
  #screen-quiz .art-panel svg { width: 100%; height: 100%; }
  #screen-quiz .art-panel img.qimg { width: 100%; height: 100%; max-height: none; }
  #screen-quiz #prompt { flex: 0 0 auto; }
  #screen-quiz #choices { flex: 0 0 auto; }
  /* The feedback block may shrink only down to its essentials
     (title + Next button); the fact text scrolls inside its own box.
     Without this floor the flex shrink crushes the block itself and
     its children spill out of the screen. */
  #screen-quiz #feedback { flex: 1 1 auto; min-height: 132px; display: flex; flex-direction: column; }
  #screen-quiz #feedback[hidden] { display: none; }
  #screen-quiz #feedback-title { flex: 0 0 auto; }
  /* Sales builds: the fact keeps at least two lines even on short
     screens (the v03 floor let long facts collapse to a one-line
     strip at 360x640); it still scrolls internally beyond that. */
  #screen-quiz #feedback-fact { flex: 1 1 auto; min-height: 42px; overflow-y: auto; }
  /* In the feedback phase the art stops growing and caps its height,
     so the fact text gets the room (the player is reading now, not
     looking at the picture). */
  #screen-quiz .dialogue:has(#feedback:not([hidden])) .art-panel { flex: 0 10 auto; max-height: 150px; min-height: 56px; }
  #screen-quiz #btn-next { flex: 0 0 auto; }
  #screen-quiz #btn-quit { flex: 0 0 auto; align-self: flex-start; }
}

/* Compact sizing for short screens (phones in portrait, small windows) */
@media (max-height: 900px) {
  .wrap { padding-top: 50px; padding-bottom: 24px; }
  #screen-quiz:not([hidden]) { height: calc(100vh - 74px); height: calc(100dvh - 74px); }
  .pico-slot.stage-pico { width: 56px; height: 56px; }
  .stage-row { margin: 8px 0 6px; }
  .bubble { padding: 8px 12px; font-size: 13px; line-height: 1.45; }
  .panel.slim { padding: 8px 12px; }
  #screen-quiz .dialogue { padding: 12px; }
  .hud-row { font-size: 13px; }
  .progress { margin-top: 6px; }
  .chips { margin-bottom: 4px; }
  #prompt { font-size: 17px; margin: 2px 0 10px; }
  #choices { gap: 8px; }
  .choice { padding: 9px 12px; font-size: 15px; }
  #feedback { margin-top: 10px; padding-top: 10px; }
  #feedback-title { font-size: 16px; margin-bottom: 4px; }
  #feedback-fact { font-size: 13.5px; line-height: 1.5; padding: 6px 10px; margin-bottom: 10px; }
  .btn.big { padding: 11px 18px; font-size: 15px; }
  .btn.small { margin-top: 8px; }
}

/* Very short screens: squeeze the fixed blocks a little further so the
   feedback phase (fact + Next button) still fits without scrolling. */
@media (max-height: 700px) {
  .pico-slot.stage-pico { width: 44px; height: 44px; }
  #screen-quiz .art-panel { min-height: 20px; }
  #screen-quiz .dialogue { padding: 10px; }
  /* In the feedback phase on very short screens, the art panel gives
     its space to the fact text and the Next button (it returns for the
     next question). This is what keeps even long prompts + long facts
     on one screen at 360x640. */
  #screen-quiz .dialogue:has(#feedback:not([hidden])) .art-panel { display: none; }
  /* Sales builds: in the feedback phase the already-read prompt and
     the answered choices slim down so the fact box keeps its two-plus
     lines on tiny screens — the exhaustive 300-question sweep found
     long-prompt + long-choice questions (Y41/Y46/K35/A16) pushing
     Next off-screen here without this. */
  #screen-quiz .dialogue:has(#feedback:not([hidden])) #prompt { font-size: 14px; line-height: 1.35; margin-bottom: 6px; }
  #screen-quiz .dialogue:has(#feedback:not([hidden])) #choices { gap: 6px; }
  #screen-quiz .dialogue:has(#feedback:not([hidden])) .choice { padding-top: 4px; padding-bottom: 4px; line-height: 1.25; }
  .stage-row { margin: 6px 0 4px; }
  #prompt { font-size: 16px; }
  .choice { padding: 7px 12px; line-height: 1.3; }
  #feedback { margin-top: 8px; }
  #feedback-fact { margin-bottom: 8px; }
  .btn.big { padding: 10px 16px; }
}

/* Answer reading screen: no floating button covers the fact.
   The sheet occupies the freed question area, with Next in its own row. */
#screen-quiz .dialogue:has(#feedback:not([hidden])) > .chips,
#screen-quiz .dialogue:has(#feedback:not([hidden])) > .art-panel,
#screen-quiz .dialogue:has(#feedback:not([hidden])) > #prompt,
#screen-quiz .dialogue:has(#feedback:not([hidden])) > #choices { display:none; }
#screen-quiz #feedback:not([hidden]) { display:flex; flex-direction:column; flex:1 1 auto; min-height:0; margin:0; padding:0; border:0; }
#feedback-question { flex:0 0 auto; font-weight:700; font-size:17px; line-height:1.4; margin:0 0 10px; }
#feedback-answer { flex:0 0 auto; font-weight:700; line-height:1.4; margin:0 0 8px; }
#screen-quiz #feedback-fact { flex:1 1 auto; min-height:5em; overflow-y:auto; font-size:16px; line-height:1.6; padding:12px; margin:0 0 12px; }
#screen-quiz #btn-next { flex:0 0 auto; position:static; width:100%; margin:0; }
@media (max-height:700px) {
  #screen-quiz:has(#feedback:not([hidden])) .stage-row { display:none; }
}
