/* =====================================================================
   ui-kit.css - Game UI kit (RPG window chrome + dialogue system)
   The cozy game layer shared by every page: window chrome, dialogue
   boxes with portraits and name tags, quest chips and progress, and
   the arcade boot screen. Loads after portal.css so the chrome recipe
   upgrades .card / .window in place. All colours from theme.css.
   ===================================================================== */

/* ---------------- window chrome (.gw recipe) --------------------- */
.gw, .card, .window {
    background: var(--card);
    border: var(--bw) solid var(--frame-ink);
    border-radius: var(--gw-radius);
    box-shadow: var(--chrome), var(--chrome-shadow);
}
.window > .win-bar {
    background: linear-gradient(var(--card-2), var(--card-warm));
    border-bottom: var(--bw) solid var(--frame-ink);
}

/* HUD chips: soft borders, gentle lift */
.hud-flowers, #app-header .crumb, .chip {
    border: var(--bw) solid var(--frame-ink);
    box-shadow: 0 2px 6px -2px rgba(122,97,73,.18);
}

/* ---------------- dialogue box ------------------------------------
   <div class="dlg dlg--vio">
     <div class="dlg-portrait">[mascot]</div>
     <div class="dlg-panel">
       <span class="dlg-name">YI FANG</span>
       <p class="dlg-text"></p>
       <span class="dlg-next">▾</span>
       <div class="dlg-choices">[.dlg-choice buttons]</div>
     </div>
   </div>                                                            */
.dlg {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: end;
    padding-top: 10px;     /* room for the overlapping name tag */
    animation: dlgIn .25s ease both;
}
@keyframes dlgIn { from { opacity: 0; transform: translateY(6px); } }
.dlg--vio  { --dlg-accent: var(--vio-deep); }
.dlg--mush { --dlg-accent: var(--mush-deep); }
.dlg--both { --dlg-accent: var(--accent-deep); }

/* bare mode: panel only, the pop modal supplies portrait + name tag */
.dlg--bare { grid-template-columns: 1fr; padding-top: 0; }
.dlg--bare .dlg-panel {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 4px 2px 10px;
}

/* in-place line swap: text/portrait/name crossfade, box never rebuilds */
.dlg .dlg-text, .dlg .dlg-portrait, .dlg .dlg-name { transition: opacity .13s ease; }
.dlg.dlg-swap .dlg-text, .dlg.dlg-swap .dlg-portrait, .dlg.dlg-swap .dlg-name { opacity: 0; }

.dlg-portrait {
    width: 76px; height: 76px;
    display: flex; align-items: flex-end; justify-content: center; gap: 4px;
    background: var(--paper-2);
    border: var(--bw) solid var(--frame-ink);
    border-radius: 14px;
    padding: 4px;
    animation: dlgBob var(--bob-dur) ease-in-out infinite;
}
.dlg--both .dlg-portrait { width: 112px; }

.dlg-panel {
    position: relative;
    background: var(--card);
    border: var(--bw) solid var(--frame-ink);
    border-radius: var(--gw-radius);
    box-shadow: var(--chrome), var(--chrome-shadow);
    padding: 18px 16px 14px;
    min-height: 84px;
}
.dlg-name {
    position: absolute; top: -10px; left: 12px;
    font-family: var(--pixel-tight);
    font-weight: 700;
    font-size: var(--px-xs);
    letter-spacing: .06em;
    text-transform: uppercase;
    line-height: 1.3;
    white-space: nowrap;
    color: #fff;
    background: var(--dlg-accent, var(--accent-deep));
    border: var(--bw) solid var(--frame-ink);
    border-radius: 8px;
    padding: 2px 10px;
    box-shadow: 0 2px 5px -2px rgba(122,97,73,.3);
}
.dlg-text {
    font-family: var(--sans);
    font-size: var(--text-base);
    line-height: 1.55;
    color: var(--ink);
    min-height: calc(1.55em * 3);   /* reserve ~3 lines so typing never reflows */
    margin: 0;
}

/* optional story image above the line (chapter slides). In sequences
   with any image the figure height is reserved up front, so the panel
   never resizes between slides. */
.dlg-fig { margin: 0 0 10px; display: flex; justify-content: center; align-items: center; }
.dlg-fig img {
    max-height: 120px; max-width: 100%;
    border-radius: var(--radius-sm);
    border: var(--bw) solid var(--frame-ink);
    object-fit: cover;
}
.dlg-fig.empty { display: none; }
.dlg--reserved-fig .dlg-fig { height: 128px; }
.dlg--reserved-fig .dlg-fig.empty { display: flex; }
.dlg--reserved-fig .dlg-fig.empty img { opacity: 0; }
.dlg-next {
    position: absolute; right: 12px; bottom: 8px;
    color: var(--dlg-accent, var(--accent-deep));
    font-size: 14px; line-height: 1;
    animation: dlgNext 1s ease-in-out infinite;
}
.dlg-next[hidden] { display: none; }

/* RPG choice buttons: rendered up front in reserved space, revealed
   with a fade once the line finishes typing (zero layout shift) */
.dlg-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; transition: opacity .18s ease; }
.dlg-choices--wait { visibility: hidden; opacity: 0; pointer-events: none; }
.dlg-choice {
    display: flex; align-items: center; gap: 8px;
    width: 100%;
    font-family: var(--pixel); font-weight: 600; font-size: var(--px-md);
    color: var(--ink); text-align: left;
    background: var(--card-2);
    border: var(--bw) solid var(--frame-ink);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    box-shadow: 0 2px 6px -2px rgba(122,97,73,.25);
    transition: transform var(--dur-fast), box-shadow var(--dur-fast);
}
.dlg-choice:active { transform: translateY(2px); box-shadow: none; }
.dlg-choice .dc-arrow { color: var(--dlg-accent, var(--accent-deep)); opacity: 0; transition: opacity var(--dur-fast); }
.dlg-choice:hover .dc-arrow, .dlg-choice:focus-visible .dc-arrow, .dlg-choice:active .dc-arrow { opacity: 1; }
.dlg-choice--accent {
    background: linear-gradient(var(--accent), var(--accent-deep));
    border-color: var(--accent-deep);
    color: #fff;
    text-shadow: 0 1px 0 rgba(0,0,0,.15);
}
.dlg-choice--accent .dc-arrow { color: #fff; }

@keyframes dlgBob  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes dlgNext { 0%,100% { transform: translateY(0); opacity: 1; } 50% { transform: translateY(2px); opacity: .35; } }

/* ---------------- quest progress bar ----------------------------- */
.qbar { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.qbar .qb-track {
    flex: 1; height: 14px;
    background: var(--card-2);
    border: var(--bw) solid var(--frame-ink);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0,0,0,.08);
}
.qbar .qb-fill {
    display: block; height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--gold));
    border-radius: 6px;
    transition: width var(--ease-bounce);
}
.qbar .qb-label {
    font-family: var(--pixel); font-weight: 700; font-size: var(--px-md);
    color: var(--accent-deep); white-space: nowrap;
}

/* ---------------- state + record chips --------------------------- */
.state-chip {
    display: inline-flex; align-items: center; gap: 4px;
    font-family: var(--pixel-tight); font-weight: 700; font-size: var(--px-xs);
    letter-spacing: .05em; text-transform: uppercase;
    border: var(--bw) solid var(--frame-ink);
    border-radius: var(--radius-pill);
    padding: 2px 8px;
}
.state-chip--new    { color: #fff; background: var(--accent); animation: chipPulse 1.6s ease-in-out infinite; }
.state-chip--done   { color: #fff; background: var(--leaf); }
.state-chip--replay { color: var(--ink-soft); background: var(--card); }
@keyframes chipPulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

.best-chip {
    display: inline-flex; align-items: center; gap: 4px;
    font-family: var(--pixel-tight); font-weight: 700; font-size: var(--px-xs); letter-spacing: .04em;
    color: var(--accent-deep);
    background: var(--card);
    border: var(--bw) solid var(--frame-ink);
    border-radius: 6px;
    padding: 2px 8px;
    white-space: nowrap;
}

/* ---------------- kahoot LIVE card -------------------------------- */
.live-card {
    position: relative;
    background: var(--card);
    border: 2px solid var(--gold);
    border-radius: var(--gw-radius);
    box-shadow: var(--chrome), var(--chrome-shadow);
    padding: 18px 16px 14px;
    margin: 10px 0 var(--space-sm);
    text-align: center;
}
.live-card .lc-tag {
    position: absolute; top: -10px; left: 12px;
    display: inline-flex; align-items: center; gap: 5px;
    font-family: var(--pixel-tight); font-weight: 700; font-size: var(--px-xs);
    letter-spacing: .05em; text-transform: uppercase; line-height: 1.25;
    color: #fff; background: var(--c-coral);
    border: var(--bw) solid var(--frame-ink);
    border-radius: 6px; padding: 1px 8px;
    box-shadow: 0 2px 5px -2px rgba(122,97,73,.3);
}
.live-card .lc-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #fff;
    animation: chipPulse 1.2s ease-in-out infinite;
}
.live-card .lc-t { font-family: var(--pixel); font-weight: 700; font-size: var(--px-lg); color: var(--accent-deep); }
.live-card .lc-note { font-size: var(--text-sm); color: var(--ink-soft); margin-top: 2px; }

/* ---------------- arcade boot screen ------------------------------
   Bridges the cream portal and the dark arcade iframes: shown over
   the embed until the game's document loads. */
.game-panel .gp-body { position: relative; }
.boot-screen {
    position: absolute; inset: 0; z-index: 5;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px;
    background: var(--arcade-ink);
    transition: opacity var(--dur-med);
}
.boot-screen.out { opacity: 0; pointer-events: none; }
.boot-screen .bs-title { font-family: var(--pixel); font-weight: 700; font-size: var(--px-lg); color: var(--arcade-cream); text-align: center; padding: 0 24px; }
.boot-screen .bs-sub { font-family: var(--pixel-tight); font-weight: 700; font-size: var(--px-xs); letter-spacing: .08em; text-transform: uppercase; color: var(--arcade-gold); }
.boot-screen .bs-dots { display: flex; gap: 6px; }
.boot-screen .bs-dots i { width: 8px; height: 8px; border-radius: 2px; background: var(--arcade-cyan); animation: bsDot 1s ease-in-out infinite; }
.boot-screen .bs-dots i:nth-child(2) { animation-delay: .15s; }
.boot-screen .bs-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bsDot { 0%,100% { opacity: .25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

/* ---------------- reduced motion --------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .dlg, .dlg-portrait, .dlg-next, .state-chip--new, .boot-screen .bs-dots i, .live-card .lc-dot { animation: none; }
    .dlg .dlg-text, .dlg .dlg-portrait, .dlg .dlg-name, .dlg-choices { transition: none; }
}
