* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #101418; font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
#app { position: fixed; inset: 0; }
/* cinematic grade: soft vignette + fine film grain */
#app::before { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: radial-gradient(ellipse at 50% 44%, rgba(0,0,0,0) 54%, rgba(18,10,4,.30) 100%); }
#app::after { content: ''; position: absolute; inset: -40%; pointer-events: none; z-index: 3; opacity: .05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
  animation: grain 1.1s steps(5) infinite; }
@keyframes grain { 0% { transform: translate(0,0) } 20% { transform: translate(-3%,2%) } 40% { transform: translate(2%,-3%) } 60% { transform: translate(-2%,-2%) } 80% { transform: translate(3%,1%) } 100% { transform: translate(0,0) } }
@media (prefers-reduced-motion: reduce) { #app::after { animation: none; } }
#scene { display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }

/* HUD */
#hud { position: absolute; top: 0; left: 0; right: 0; padding: 10px 14px; pointer-events: none; z-index: 5; }
.hud-top { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.hud-box { background: rgba(10,14,20,.72); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 10px; padding: 6px 14px; font-weight: 700; font-size: 16px; min-width: 110px; text-align: center; backdrop-filter: blur(4px); }
#hud-pos { background: rgba(200,30,40,.85); }
.hud-bars { max-width: 560px; margin: 8px auto 0; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.bar-label { color: #fff; font-size: 11px; font-weight: 700; width: 130px; text-align: right; text-shadow: 0 1px 3px #000; }
.bar { position: relative; flex: 1; height: 14px; background: rgba(0,0,0,.55); border-radius: 8px; border: 1px solid rgba(255,255,255,.3); overflow: hidden; }
#progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #e11d2e, #ff6b6b, #fff); border-radius: 8px; transition: width .15s; }
#progress-flag { position: absolute; right: 2px; top: -3px; font-size: 14px; }
.bar.stamina { height: 12px; }
#stamina-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #22c55e, #a3e635); border-radius: 8px; transition: width .15s; }
#stamina-fill.low { background: linear-gradient(90deg, #e11d2e, #f97316); }
#hint { text-align: center; color: #ffe; font-size: 12px; margin-top: 8px; text-shadow: 0 1px 4px #000; background: rgba(0,0,0,.35); display: inline-block; padding: 4px 12px; border-radius: 8px; }
#hud { text-align: center; }

/* Overlays */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8,10,14,.62); z-index: 10; padding: 16px; }
.card { background: linear-gradient(180deg, #fff, #ffe9e9); border-radius: 18px; padding: 26px 28px; max-width: 560px; width: 100%; text-align: center; border-top: 10px solid #e11d2e; box-shadow: 0 20px 60px rgba(0,0,0,.5); max-height: 92vh; overflow-y: auto; }
.card h1 { color: #c1121f; letter-spacing: 2px; font-size: 30px; }
.subtitle { color: #444; margin: 4px 0 12px; font-weight: 600; }
.rules { text-align: left; font-size: 14px; color: #222; line-height: 1.5; }
.rules .en { color: #555; font-size: 13px; margin-top: 6px; }
.rules .keys { margin-top: 8px; color: #666; font-size: 12px; }
kbd { background: #222; color: #fff; border-radius: 5px; padding: 1px 7px; font-size: 12px; font-family: inherit; }
.bunting-emoji { font-size: 26px; }
.btn-big { margin-top: 16px; background: #c1121f; color: #fff; border: none; border-radius: 12px; padding: 14px 30px; font-size: 18px; font-weight: 800; cursor: pointer; letter-spacing: 1px; box-shadow: 0 6px 0 #7a0b13; }
.btn-big:active { transform: translateY(3px); box-shadow: 0 2px 0 #7a0b13; }
.btn-small { margin-top: 10px; margin-left: 8px; background: #eee; border: 1px solid #ccc; border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; }
#result-list { text-align: left; margin: 12px auto; max-width: 340px; font-size: 16px; line-height: 1.9; }
#result-list li.me { font-weight: 800; color: #c1121f; }
#countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 110px; font-weight: 900; color: #fff; text-shadow: 0 0 30px #e11d2e, 0 4px 0 #000; z-index: 9; pointer-events: none; }

/* Touch */
#touch { position: absolute; bottom: 14px; left: 0; right: 0; display: flex; justify-content: space-between; padding: 0 16px; z-index: 6; pointer-events: none; }
.tbtn { pointer-events: auto; width: 96px; height: 84px; border-radius: 18px; border: 2px solid rgba(255,255,255,.5); background: rgba(193,18,31,.8); color: #fff; font-size: 28px; font-weight: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; user-select: none; -webkit-user-select: none; }
.tbtn span { font-size: 11px; font-weight: 700; }
.tbtn.mid { background: rgba(20,90,200,.8); width: 84px; }
.tbtn:active { transform: scale(.93); }
#credit { position: absolute; bottom: 6px; right: 10px; color: rgba(255,255,255,.5); font-size: 11px; z-index: 4; pointer-events: none; }
@media (max-width: 600px) {
  .bar-label { display: none; }
  .card h1 { font-size: 22px; }
  #hint { display: none; }
}
