* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; font-family: 'Trebuchet MS', 'Segoe UI', Arial, sans-serif; color: #fff; user-select: none; }
#game canvas { display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.label { font-size: 11px; letter-spacing: 2px; font-weight: bold; opacity: 0.85; }
.bar { height: 12px; background: rgba(0,0,0,0.55); border: 2px solid rgba(255,255,255,0.7); border-radius: 7px; overflow: hidden; }
.bar > div { height: 100%; width: 50%; background: #2ecc71; transition: width 0.08s linear; }

#leftcol { position: absolute; top: 16px; left: 16px; max-width: 380px; }
#objective { background: rgba(0,40,90,0.78); border-left: 6px solid #ffd400; padding: 10px 14px; border-radius: 4px; }
.task { margin-top: 8px; background: rgba(0,70,70,0.82); border-left: 6px solid #3ff0e0; padding: 7px 12px; border-radius: 4px; font-size: 15px; text-shadow: 1px 1px 0 #000; }
.task.escort { background: rgba(20,80,20,0.82); border-color: #6f6; }
.task .who { font-size: 11px; letter-spacing: 1.5px; font-weight: bold; opacity: 0.85; }
.task .tt { float: right; font-family: 'Courier New', monospace; font-weight: bold; color: #ffd400; font-size: 18px; margin-left: 10px; }
.task.urgent { border-color: #f33; animation: pulse 0.5s infinite; }
.task.urgent .tt { color: #ff5050; }
#strikes { font-size: 15px; margin: -4px 0 8px; text-shadow: 1px 1px 0 #000; }
#strikes .x { color: #ff4040; font-weight: 900; }
#strikes .o { color: rgba(255,255,255,0.35); }
#objText { font-size: 17px; margin-top: 3px; text-shadow: 1px 1px 0 #000; }
#topright { position: absolute; top: 16px; right: 16px; text-align: right; }
#clock { font-family: 'Courier New', monospace; font-size: 30px; font-weight: bold; color: #7CFC00; background: #111; padding: 2px 10px; border-radius: 4px; display: inline-block; border: 2px solid #444; }
#score { font-size: 15px; margin: 4px 0 8px; text-shadow: 1px 1px 0 #000; }
#minimap { background: rgba(10,20,30,0.75); border: 2px solid rgba(255,255,255,0.6); border-radius: 6px; display: block; margin-left: auto; }

#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255,255,255,0.85); box-shadow: 0 0 2px #000; }
#prompt { position: absolute; left: 50%; top: calc(50% + 26px); transform: translateX(-50%); font-size: 18px; font-weight: bold; text-shadow: 2px 2px 0 #000; white-space: nowrap; }
#holdbar { position: absolute; left: 50%; top: calc(50% + 56px); width: 180px; margin-left: -90px; height: 10px; background: rgba(0,0,0,0.5); border: 2px solid #fff; border-radius: 6px; overflow: hidden; display: none; }
#holdFill { height: 100%; width: 0; background: #ffd400; }

#stability { position: absolute; bottom: 28px; left: 50%; width: 320px; margin-left: -160px; text-align: center; }
#stability .bar { height: 16px; margin-top: 4px; }
#stability.danger { animation: shake 0.15s infinite; }

#dashTimer { position: absolute; top: 14px; left: 50%; width: 360px; margin-left: -180px; text-align: center; background: rgba(90,40,10,0.8); padding: 8px 12px; border-radius: 8px; border: 3px solid #ffb347; }
#dashTime { font-size: 40px; font-weight: bold; font-family: 'Courier New', monospace; color: #ffde59; text-shadow: 2px 2px 0 #000; }
#dashTimer.critical { animation: pulse 0.5s infinite; border-color: #ff3b3b; }
#dashTimer.critical #dashTime { color: #ff5050; }
#dashFill { background: linear-gradient(90deg, #6b3d10, #c47a2c); }

#alert { position: absolute; top: 140px; left: 50%; transform: translateX(-50%); font-size: 26px; font-weight: 900; color: #fff; text-shadow: 3px 3px 0 #a00, -1px -1px 0 #000; opacity: 0; transition: opacity 0.2s; white-space: nowrap; }
#alert.show { opacity: 1; animation: pulse 0.4s infinite; }

#captions { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); width: min(760px, 90vw); text-align: center; }
.cap { background: rgba(0,0,0,0.68); display: inline-block; padding: 6px 14px; margin: 3px 0; border-radius: 5px; font-size: 18px; transition: opacity 0.4s; }
.cap b { color: #ffd400; }
.cap.npc b { color: #ff8080; }
.cap.sys b { color: #7fd3ff; }

#convo { position: absolute; bottom: 120px; left: 50%; width: min(620px, 92vw); transform: translateX(-50%); background: rgba(255,255,255,0.95); color: #111; border-radius: 12px; padding: 14px 18px; border: 4px solid #c00; box-shadow: 0 8px 0 rgba(0,0,0,0.4); }
#convoName { font-weight: 900; color: #c00; font-size: 15px; letter-spacing: 1px; }
#convoLine { font-size: 21px; margin: 6px 0 10px; }
#convo .mash { font-size: 14px; margin-bottom: 6px; animation: pulse 0.6s infinite; }
#convo .bar { border-color: #333; }
#convoFill { background: #ffb400; }

#bigtitle { position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%); font-size: 64px; font-weight: 900; text-align: center; color: #ffde59; text-shadow: 4px 4px 0 #5a2d0c, -2px -2px 0 #000; opacity: 0; transition: opacity 0.3s; white-space: nowrap; }
#bigtitle.show { opacity: 1; animation: wobble 0.6s infinite; }

#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(110,50,0,0.85) 100%); opacity: 0; }
#flash { position: fixed; inset: 0; pointer-events: none; background: #5a2d0c; opacity: 0; }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(ellipse at center, rgba(0,60,120,0.88), rgba(0,10,25,0.97)); text-align: center; padding: 16px; z-index: 10; }
.logo { transform: rotate(-3deg); margin-bottom: 18px; }
.logo-top { font-size: clamp(36px, 8vw, 84px); font-weight: 900; color: #fff; background: #00539f; padding: 4px 24px; border: 6px solid #ffd400; border-bottom: none; letter-spacing: 4px; }
.logo-bottom { font-size: clamp(48px, 11vw, 120px); font-weight: 900; color: #ffd400; background: #c8102e; padding: 0 24px; border: 6px solid #ffd400; letter-spacing: 8px; text-shadow: 5px 5px 0 #6b0010; }
.logo-sub { margin-top: 10px; font-size: 22px; font-style: italic; color: #cfe8ff; }
.blurb { max-width: 600px; font-size: 18px; line-height: 1.5; color: #e6f0ff; }
button { pointer-events: auto; font-family: inherit; font-size: 24px; font-weight: 900; padding: 14px 40px; margin: 14px; background: #ffd400; color: #111; border: none; border-radius: 10px; box-shadow: 0 6px 0 #a38600; cursor: pointer; letter-spacing: 2px; }
button:hover { background: #ffe34d; transform: translateY(-2px); }
button:active { transform: translateY(4px); box-shadow: 0 2px 0 #a38600; }
.controls { margin-top: 16px; font-size: 15px; color: #bcd; line-height: 1.9; }
.controls b { background: #fff; color: #111; padding: 1px 7px; border-radius: 4px; }
.card { background: #fdfaf0; color: #222; max-width: 640px; padding: 24px 32px; border-radius: 12px; border: 6px solid #ffd400; text-align: left; box-shadow: 0 10px 0 rgba(0,0,0,0.4); }
.card h2 { margin-top: 0; color: #00539f; }
.card p { font-size: 17px; line-height: 1.5; }
.card button { display: block; margin: 16px auto 0; }
.stats { width: 100%; border-collapse: collapse; font-size: 17px; margin: 10px 0; }
.stats td { padding: 5px 4px; border-bottom: 1px solid #ddd; }
.stats td:last-child { text-align: right; font-weight: bold; }
.grade { font-size: 72px; font-weight: 900; text-align: center; color: #c8102e; margin: 0; line-height: 1; }
.end-lose { border-color: #6b3d10 !important; background: #f3e4d0 !important; }
.end-lose h2 { color: #6b3d10 !important; }

.card { max-height: 92vh; overflow-y: auto; }
.card.wide { max-width: 860px; width: 100%; }
.btnrow { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.card .btnrow button { display: inline-block; margin: 14px 8px 0; }
button.small { font-size: 16px; padding: 10px 22px; background: #e8eef7; box-shadow: 0 5px 0 #8a99ad; }
button.small:hover { background: #fff; }
.hint { font-size: 14px !important; color: #666; text-align: center; margin: 6px 0; }
.settings { margin: 10px 0; }
.settings label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; margin: 14px 0; font-size: 16px; font-weight: bold; }
.settings label b { color: #00539f; font-family: 'Courier New', monospace; }
.settings input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: #c8102e; height: 22px; cursor: pointer; }
.lb-entry { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 12px 0 4px; flex-wrap: wrap; }
.lb-entry input { font-family: inherit; font-size: 18px; padding: 10px 12px; border: 3px solid #00539f; border-radius: 8px; width: 220px; }
.lb-entry button { margin: 0 !important; }
.lb-err { text-align: center; color: #c8102e; font-weight: bold; font-size: 15px; min-height: 1em; }
.lb-entry button:disabled { opacity: 0.6; cursor: wait; }
.lb-saved { text-align: center; font-weight: bold; color: #2c6e49; font-size: 17px; margin: 10px 0; }
.board { width: 100%; border-collapse: collapse; font-size: 15px; margin-top: 8px; }
.board th { text-align: left; background: #00539f; color: #fff; padding: 6px 8px; font-size: 12px; letter-spacing: 1px; }
.board td { padding: 6px 8px; border-bottom: 1px solid #ddd; }
.board tr:nth-child(even) td { background: #f3efe2; }
.board tr.me td { background: #ffe680 !important; font-weight: bold; }
.board .num { text-align: right; font-family: 'Courier New', monospace; }
.board .res-win { color: #2c6e49; } .board .res-poo { color: #6b3d10; } .board .res-sacked { color: #c8102e; }
.board-empty { text-align: center; color: #777; padding: 20px; }
.board-wrap { overflow-x: auto; }

@keyframes pulse { 50% { opacity: 0.6; } }
@keyframes shake { 0% { transform: translateX(-2px); } 50% { transform: translateX(2px); } 100% { transform: translateX(-2px); } }
@keyframes wobble { 0%, 100% { transform: translate(-50%, -50%) rotate(-3deg) scale(1); } 50% { transform: translate(-50%, -50%) rotate(3deg) scale(1.06); } }

@media (max-width: 900px) {
  #dashTimer { top: 130px; width: 300px; margin-left: -150px; }
  #alert { top: 240px; font-size: 20px; }
}
@media (max-width: 700px) {
  #minimap { width: 130px; height: 114px; }
  #bigtitle { font-size: 34px; }
  #objective { max-width: 60vw; }
}
