/* Game screen */
.screen-game { background: #9fce6b; }
.world-canvas { position: absolute; inset: 0; display: block; touch-action: none; cursor: pointer; }
.grain { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: multiply; opacity: 0.45;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(120, 80, 30, 0.3) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.35 0 0 0 0 0.2 0 0 0 0.3 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
.hud { position: absolute; inset: 0; pointer-events: none; --hud-pad: 18px; }
.hud > * { pointer-events: auto; position: absolute; }

.hud-title { top: var(--hud-pad); left: max(var(--hud-pad), var(--safe-left)); display: flex; align-items: flex-start; gap: 12px; padding: 6px 40px 22px 6px; max-width: 46vw; background: radial-gradient(ellipse at 30% 40%, rgba(239, 228, 204, 0.95) 45%, rgba(239, 228, 204, 0) 72%); pointer-events: none; }
.hud-title h1 { font-family: var(--font-brush); font-weight: 400; font-size: clamp(26px, 4.4vh, 44px); line-height: 1; color: #2a211c; word-break: break-word; }
.hud-title p { font-size: 13px; letter-spacing: 3px; text-transform: uppercase; margin-top: 4px; color: #2a211c; font-weight: 700; }

.hud-side { top: var(--hud-pad); right: max(var(--hud-pad), var(--safe-right)); width: min(300px, 34vw); display: flex; flex-direction: column; align-items: flex-end; gap: 18px; pointer-events: none; }
.hud-side > * { pointer-events: auto; }
.scroll { position: relative; width: 100%; padding: 18px 20px 14px; color: #2a211c; background: linear-gradient(90deg, #f6eedb, #efe2c4 50%, #f6eedb); box-shadow: 0 10px 24px rgba(60, 40, 20, 0.25); animation: unroll 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both; transform-origin: top; }
.scroll::before, .scroll::after { content: ''; position: absolute; left: -9px; right: -9px; height: 11px; border-radius: 6px; background: linear-gradient(#5b3a22, #2b1a10); }
.scroll::before { top: -5px; } .scroll::after { bottom: -5px; }
.scroll-chapter { font-size: 11px; letter-spacing: 4px; text-transform: uppercase; color: #c0392b; }
.scroll h2 { font-family: var(--font-brush); font-weight: 400; font-size: clamp(20px, 3.4vh, 28px); line-height: 1.05; margin: 4px 0; }
.scroll p { font-size: 14px; line-height: 1.35; }
.brush-bar { position: relative; height: 14px; margin: 10px 0 5px; background: rgba(42, 33, 28, 0.1); border-radius: 8px 3px 8px 3px; overflow: hidden; }
.brush-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: #2a211c; border-radius: 8px 30px 6px 24px; filter: url(#rough); transition: width 0.5s ease-out; }
.scroll.is-done .brush-bar i { background: #c0392b; }
.scroll-count { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: rgba(42, 33, 28, 0.7); }
.scroll-count span:last-child { color: #c0392b; text-align: right; }
.hud-menu { display: flex; gap: 10px; }

.hotbar { bottom: calc(var(--hud-pad) + var(--safe-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 22px; align-items: flex-end; }
.slot { width: 72px; height: 72px; border-radius: 50%; background: rgba(239, 228, 204, 0.86); }
.slot canvas { width: 44px; height: 44px; position: relative; z-index: 1; }
.slot-key { position: absolute; bottom: -6px; right: -16px; z-index: 2; padding: 2px 7px; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; background: #2a211c; color: #efe4cc; }
.slot::before { border-color: #2a211c; border-right-color: transparent; }

.items-button { left: max(var(--hud-pad), var(--safe-left)); bottom: calc(var(--hud-pad) + var(--safe-bottom)); width: 78px; height: 78px; border-radius: 50%; background: rgba(239, 228, 204, 0.9); font-family: var(--font-brush); font-size: 19px; color: #2a211c; z-index: 3; }
.items-button::before { border-color: #c0392b; border-right-color: transparent; }

.touch-controls { inset: 0; pointer-events: none; display: none; }
.touch-controls.is-visible { display: block; }
.touch-controls > * { pointer-events: auto; position: absolute; }
.dpad { left: max(var(--hud-pad), var(--safe-left)); bottom: calc(110px + var(--safe-bottom)); width: 156px; height: 156px; }
.dpad-button { position: absolute; width: 54px; height: 54px; border: none; border-radius: 50%; background: rgba(239, 228, 204, 0.82); color: #2a211c; font-size: 24px; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(42, 33, 28, 0.55), 0 3px 8px rgba(40, 20, 10, 0.2); touch-action: none; }
.dpad-button.is-pressed { background: #2a211c; color: #efe4cc; }
.dpad .up { left: 51px; top: 0; } .dpad .down { left: 51px; bottom: 0; } .dpad .left { left: 0; top: 51px; } .dpad .right { right: 0; top: 51px; }
.actions { right: max(var(--hud-pad), var(--safe-right)); bottom: calc(var(--hud-pad) + var(--safe-bottom)); display: flex; gap: 12px; align-items: flex-end; }
.action-button { width: 68px; height: 68px; border-radius: 50%; background: rgba(239, 228, 204, 0.86); font-size: 14px; color: #2a211c; touch-action: none; }
.action-button.is-pressed { transform: scale(0.92); }
.action-button.destroy { width: 104px; height: 104px; font-family: var(--font-brush); font-size: 24px; color: #c0392b; }
.action-button.destroy::before { border: 7px solid #c0392b; border-right-color: transparent; }
.hud.is-touch .slot-key { display: none; }

.items-panel { top: 0; bottom: 0; left: 0; z-index: 5; width: min(500px, 54vw); display: flex; flex-direction: column; color: #2a211c; background: repeating-linear-gradient(90deg, #f3ead6 0 calc(25% - 1px), rgba(60, 40, 20, 0.14) calc(25% - 1px) 25%), #f3ead6; box-shadow: 18px 0 40px rgba(60, 40, 20, 0.3); transform: translateX(-106%); transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1); visibility: hidden; }
.items-panel.is-open { transform: none; visibility: visible; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px max(22px, var(--safe-left)); }
.panel-head h2 { font-family: var(--font-brush); font-weight: 400; font-size: 32px; }
.panel-head .icon-button { color: #2a211c; box-shadow: inset 0 0 0 2px rgba(42, 33, 28, 0.2); }
.slot-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 6px 20px 0 max(22px, var(--safe-left)); }
.slot-tab { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: none; border-radius: 12px; background: rgba(255, 255, 255, 0.5); box-shadow: inset 0 0 0 2px rgba(42, 33, 28, 0.18); cursor: pointer; text-align: left; color: #2a211c; }
.slot-tab.is-active { box-shadow: inset 0 0 0 3px #c0392b; background: rgba(192, 57, 43, 0.08); }
.slot-tab canvas { width: 40px; height: 40px; flex: none; }
.slot-tab-text { display: grid; line-height: 1.15; min-width: 0; }
.slot-tab-text small { font-size: 12px; color: rgba(42, 33, 28, 0.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-tab kbd { margin-left: auto; background: #2a211c; color: #efe4cc; }
.panel-hint { padding: 8px 20px 4px max(22px, var(--safe-left)); font-size: 13px; color: rgba(42, 33, 28, 0.7); }
.panel-groups { flex: 1; overflow-y: auto; padding: 0 16px 24px max(18px, var(--safe-left)); overscroll-behavior: contain; touch-action: pan-y; }
.item-group h3 { font-family: var(--font-brush); font-weight: 400; font-size: 22px; margin: 14px 4px 6px; display: inline-block; background: linear-gradient(transparent 62%, rgba(192, 57, 43, 0.4) 62% 88%, transparent 88%); }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.item { position: relative; display: grid; justify-items: center; align-content: start; gap: 3px; padding: 8px 4px 6px; border: none; border-radius: 8px; background: transparent; cursor: pointer; font-size: 12px; line-height: 1.15; text-align: center; color: #2a211c; }
.item canvas { width: 46px; height: 46px; }
.item:hover { background: rgba(42, 33, 28, 0.07); }
.item.is-assigned { box-shadow: inset 0 0 0 2px #c0392b; background: rgba(192, 57, 43, 0.06); }
.item.is-assigned::after { content: attr(data-slot); position: absolute; top: 3px; right: 4px; padding: 0 5px; border-radius: 4px; background: #c0392b; color: #f6efe4; font-size: 10px; font-weight: 700; }

.level-banner { left: 50%; top: 38%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 4px; padding: 16px 40px; opacity: 0; pointer-events: none; background: radial-gradient(ellipse, rgba(239, 228, 204, 0.92) 40%, rgba(239, 228, 204, 0) 72%); color: #2a211c; }
.level-banner strong { font-family: var(--font-brush); font-weight: 400; font-size: clamp(30px, 6vh, 52px); }
.level-banner span { font-size: 14px; letter-spacing: 3px; text-transform: uppercase; }
.level-banner.is-showing { animation: banner 2.2s ease-out; }
@keyframes banner { 0% { opacity: 0; filter: blur(6px); } 15%, 70% { opacity: 1; filter: none; } 100% { opacity: 0; } }

[data-theme="dark"] .hud-title { background: radial-gradient(ellipse at 30% 40%, rgba(29, 30, 43, 0.9) 45%, rgba(29, 30, 43, 0) 72%); }
[data-theme="dark"] .hud-title h1, [data-theme="dark"] .hud-title p { color: #efe6d4; }

/* Mini games */
.minigame { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: max(10px, env(safe-area-inset-top, 0px)) max(10px, var(--safe-right)) max(10px, var(--safe-bottom)) max(10px, var(--safe-left)); background: rgba(30, 20, 12, 0.55); backdrop-filter: blur(3px); }
.mg-frame { width: min(1100px, 100%); height: 100%; max-height: 760px; display: flex; flex-direction: column; border-radius: 10px; overflow: hidden; background: var(--paper); box-shadow: var(--shadow); animation: unroll 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
.mg-head { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-bottom: 2px solid var(--ink-faint); }
.mg-title { display: flex; align-items: center; gap: 10px; }
.mg-title canvas { width: 44px; height: 44px; }
.mg-title h2 { font-family: var(--font-brush); font-weight: 400; font-size: 26px; }
.mg-stats { margin-left: auto; display: flex; gap: 18px; font-size: 16px; }
.mg-score b { font-family: var(--font-body); font-weight: 700; font-size: 22px; color: var(--vermilion); }
.mg-status { color: var(--ink-soft); }
.mg-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; display: grid; place-items: center; }
.mg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.mg-card { width: min(440px, 90%); padding: 26px; text-align: center; display: grid; gap: 10px; background: var(--paper-light); border-radius: 10px; box-shadow: var(--shadow); }
.mg-card h3 { font-family: var(--font-brush); font-weight: 400; font-size: 34px; }
.mg-kicker { font-size: 12px; letter-spacing: 4px; text-transform: uppercase; color: var(--vermilion); }
.mg-big { font-family: var(--font-brush); font-size: 72px; line-height: 1; }
.mg-best { color: var(--ink-soft); font-size: 14px; }
.mg-card-actions { display: flex; justify-content: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.mg-loading { color: var(--ink-soft); font-size: 18px; }

.mg-memory { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(6px, 1.4vh, 12px); width: min(560px, 92%, 80vh); aspect-ratio: 1; padding: 10px; }
.memory-card { position: relative; border: none; border-radius: 10px; cursor: pointer; perspective: 600px; background: transparent; }
.memory-back, .memory-face { position: absolute; inset: 0; border-radius: 10px; backface-visibility: hidden; transition: transform 0.35s; display: grid; place-items: center; }
.memory-back { background: var(--vermilion); box-shadow: inset 0 0 0 4px #f6efe4, inset 0 0 0 7px var(--vermilion); }
.memory-back::after { content: 'i'; font-family: var(--font-brush); font-size: clamp(20px, 5vh, 40px); color: #f6efe4; }
.memory-face { background: #f7f0e1; box-shadow: inset 0 0 0 2px rgba(42, 33, 28, 0.2); transform: rotateY(180deg); }
.memory-face canvas { width: 80%; height: 80%; }
.memory-card.is-open .memory-back { transform: rotateY(180deg); }
.memory-card.is-open .memory-face { transform: rotateY(0); }
.memory-card.is-matched .memory-face { box-shadow: inset 0 0 0 3px var(--jade); }

.mg-lanterns { display: grid; justify-items: center; gap: 30px; }
.mg-lantern-hint { font-family: var(--font-brush); font-size: 30px; }
.lantern-row { display: flex; gap: clamp(16px, 4vw, 48px); }
.lantern { position: relative; display: grid; justify-items: center; border: none; background: none; cursor: pointer; --lantern: #e8453c; }
.lantern-cap { width: 54px; height: 12px; border-radius: 4px; background: #2a211c; }
.lantern-body { width: clamp(70px, 11vw, 110px); height: clamp(96px, 20vh, 150px); border-radius: 46%; background: var(--lantern); filter: brightness(0.55) saturate(0.8); box-shadow: inset 0 0 0 3px #2a211c; transition: filter 0.12s, box-shadow 0.12s; }
.lantern.is-lit .lantern-body { filter: brightness(1.25) saturate(1.2); box-shadow: inset 0 0 0 3px #2a211c, 0 0 40px 12px var(--lantern); }
.lantern kbd { margin-top: 8px; }

.mg-moles { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(8px, 2vh, 18px); width: min(520px, 90%, 72vh); aspect-ratio: 1; }
.mole-hole { position: relative; overflow: hidden; border: none; border-radius: 50% 50% 18px 18px; background: radial-gradient(ellipse at 50% 80%, #3a2a20 35%, #7d5838 36%, #8d6440 60%, #9fce6b 61%); cursor: pointer; touch-action: none; }
.mole { position: absolute; left: 50%; bottom: 10%; width: 70%; aspect-ratio: 1; transform: translate(-50%, 85%); transition: transform 0.12s ease-out; }
.mole canvas { width: 100%; height: 100%; }
.mole-hole.is-up .mole { transform: translate(-50%, 8%); }
.mole-hole.is-golden .mole { filter: sepia(1) saturate(4) hue-rotate(5deg) brightness(1.15); }
.mole-hole.is-bopped { transform: scale(0.96); }
.mole-hole kbd { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); z-index: 2; opacity: 0.75; }

.mg-shadows { display: grid; justify-items: center; gap: 14px; width: min(640px, 94%); }
.shadow-frame { width: min(240px, 34vh); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle, #fbf5e8 55%, #efe2c4); box-shadow: inset 0 0 0 5px #2a211c; }
.shadow-canvas { width: 82%; height: 82%; }
.shadow-feedback { font-family: var(--font-brush); font-size: 24px; text-align: center; }
.shadow-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.shadow-option { border-radius: 12px; }
.shadow-option.is-right { background: var(--jade); color: #fff; box-shadow: none; }
.shadow-option.is-wrong { background: var(--vermilion); color: #fff; box-shadow: none; }

/* Phones in landscape */
@media (max-height: 520px) {
  .hud { --hud-pad: 10px; }
  .hud-title .seal { width: 40px; height: 40px; font-size: 22px; }
  .hud-title p { font-size: 11px; letter-spacing: 2px; }
  .hud-side { width: min(240px, 32vw); gap: 12px; }
  .scroll { padding: 12px 14px 10px; }
  .scroll p { font-size: 12px; }
  .stamp { width: 38px; height: 38px; font-size: 22px; }
  .slot { width: 54px; height: 54px; }
  .slot canvas { width: 32px; height: 32px; }
  .items-button { width: 62px; height: 62px; font-size: 16px; }
  .dpad { transform: scale(0.78); transform-origin: bottom left; bottom: calc(80px + var(--safe-bottom)); }
  .action-button { width: 56px; height: 56px; font-size: 12px; }
  .action-button.destroy { width: 82px; height: 82px; font-size: 20px; }
  .modal { padding: 18px 18px 14px; }
  .modal-title { font-size: 24px; }
  .character-card { padding: 6px 6px 8px; }
  .character-card canvas { width: 52px; height: 52px; }
  .character-card small { display: none; }
  .choice small { font-size: 12px; }
  .mg-head { padding: 4px 10px; }
  .mg-title h2 { font-size: 20px; }
}

.rotate-prompt { position: fixed; inset: 0; z-index: 100; display: none; place-items: center; align-content: center; gap: 18px; text-align: center; background: var(--paper); font-family: var(--font-brush); font-size: 26px; padding: 30px; }
@media (orientation: portrait) and (pointer: coarse) {
  .rotate-prompt { display: grid; }
}
