/* Subnet & Sorcery - styles. Dark "night in the tavern" theme, parchment panels, gold trim. */
:root {
  --bg: #17111d;
  --bg2: #221a2b;
  --panel: #2a2033;
  --line: #6e5687;
  --gold: #f0c75e;
  --text: #ece0c8;
  --muted: #b9a7cf;
  --green: #8fe39a;
  --red: #ff8a8a;
  --orange: #ffb35c;
  --term: #0b0b0b;
  --term-text: #9df29d;
  --serif: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  --mono: Consolas, Menlo, "DejaVu Sans Mono", monospace;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at top, #2b1f36 0%, var(--bg) 700px) no-repeat, var(--bg); color: var(--text); font-family: var(--serif); font-size: 17px; line-height: 1.5; }
#app { max-width: 1100px; margin: 0 auto; padding: 16px; }
header { text-align: center; }
h1 { font-size: 46px; color: var(--gold); margin: 6px 0 0; letter-spacing: 1px; text-shadow: 0 2px 0 #000; }
h1 .amp { font-style: italic; color: var(--text); }
h2 { color: var(--gold); margin: 6px 0; }
h3 { color: var(--gold); margin: 4px 0 8px; font-size: 19px; }
.subtitle { font-style: italic; color: var(--muted); margin: 0 0 12px; }
.small { font-size: 14px; color: var(--muted); }
.big { font-size: 20px; }
code { font-family: var(--mono); color: var(--term-text); }
.hidden { display: none !important; }
.print-only { display: none; }
.banner { display: inline-block; background: #4a3416; border: 1px solid var(--gold); padding: 2px 12px; border-radius: 12px; font-size: 13px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin: 12px 0; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.center { max-width: 560px; margin: 24px auto; text-align: center; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.row.left { justify-content: flex-start; }
.bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.bar .buttons { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 8px; }

button, .btn { background: #5a3d6e; color: #f6ecd6; border: 2px solid var(--gold); padding: 8px 14px; cursor: pointer; font-family: inherit; font-size: 16px; border-radius: 6px; }
button:hover, .btn:hover { background: #7a5390; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button.quiet, .btn.quiet { background: transparent; border-color: var(--line); }
button.quiet:hover, .btn.quiet:hover { border-color: var(--gold); }
button:disabled { opacity: .45; cursor: not-allowed; }
input { padding: 8px 10px; background: #1a1420; color: var(--text); border: 1px solid var(--line); border-radius: 6px; font-family: inherit; font-size: 16px; }

/* ----- profiles ----- */
.card { background: var(--bg2); border: 1px solid var(--line); padding: 10px 12px; margin: 8px 0; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; }
.card .who { font-size: 18px; }
.card .meta { font-size: 13px; color: var(--muted); }

/* ----- world map ----- */
#badges { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }
.badge { background: #3b2a12; border: 1px solid var(--gold); border-radius: 14px; padding: 2px 10px; font-size: 14px; }
.region { margin: 14px 0 22px; }
.region-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 10px; }
.region-head h3 { margin: 0; font-size: 22px; }
.paths { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.path { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.path h4 { margin: 0 0 6px; color: var(--muted); font-weight: normal; font-style: italic; }
.level-btn { display: block; width: 100%; text-align: left; margin: 6px 0; font-size: 15px; }
.level-btn .lvl-meta { display: block; font-size: 12px; color: var(--muted); }
.level-btn.done { border-color: var(--green); }
.level-btn.done::after { content: " ✔"; color: var(--green); }
.level-btn.locked::before { content: "🔒 "; }
.level-btn.boss { border-width: 3px; background: #5a2030; }
.level-btn.boss:hover:not(:disabled) { background: #7a2a40; }
.upcoming { opacity: .55; }

/* ----- lesson & trial ----- */
.spell { background: var(--bg2); border-left: 4px solid var(--gold); padding: 10px 12px; margin: 10px 0; border-radius: 4px; }
.spell .cmd { font-family: var(--mono); color: var(--term-text); font-size: 17px; }
.spell .short, .spell .mode { color: var(--muted); font-size: 13px; }
.spell .example { font-family: var(--mono); color: var(--term-text); background: var(--term); padding: 4px 8px; border-radius: 4px; display: inline-block; margin-top: 4px; }
.spell .new { background: var(--gold); color: #000; font-size: 11px; padding: 1px 6px; border-radius: 8px; margin-left: 6px; font-family: var(--serif); }
.trial-line { display: flex; align-items: center; background: var(--term); border: 2px solid var(--gold); border-radius: 6px; padding: 6px 10px; font-family: var(--mono); color: var(--term-text); }
.trial-line input { flex: 1; background: transparent; border: none; color: var(--term-text); font-family: var(--mono); outline: none; padding: 4px 6px; }
.correct { color: var(--green); }
.wrong { color: var(--red); }

/* ----- quest ----- */
.story p { margin: 0 0 6px; }
details summary { cursor: pointer; color: var(--gold); font-size: 15px; }
details p { color: var(--muted); font-size: 15px; }
#level-body { display: grid; grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr); gap: 14px; align-items: start; }
#map-wrap { background: #1d1526; border: 1px solid var(--line); border-radius: 8px; }
#net-map { width: 100%; height: auto; display: block; }
#quest-panel { margin: 0; }
#task-list { padding-left: 20px; margin: 0 0 12px; }
#task-list li { margin: 4px 0; }
#task-list li.done { color: var(--green); }
#task-list li.done::marker { content: "✔ "; }
#oracle { border-top: 1px solid var(--line); padding-top: 8px; margin-bottom: 10px; }
#riddle-input { flex: 1; min-width: 120px; }
#hint-text { font-style: italic; color: var(--muted); }

.device { cursor: pointer; }
.device .halo { fill: #2f2340; stroke: var(--line); stroke-width: 2; }
.device:hover .halo, .device.selected .halo { stroke: var(--gold); stroke-width: 3; }
.device .icon { font-size: 30px; }
.device .label { fill: var(--text); font-size: 14px; font-family: var(--serif); }
.device .addr { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.intf-label { fill: var(--muted); font-size: 10px; font-family: var(--mono); }
.link-up { stroke: var(--gold); stroke-width: 3; }
.link-down { stroke: var(--red); stroke-width: 3; stroke-dasharray: 6 6; }
.link-lossy { stroke: var(--orange); stroke-width: 3; stroke-dasharray: 2 5; }

#terminal { background: var(--term); color: var(--term-text); font-family: var(--mono); margin-top: 14px; border: 2px solid var(--gold); border-radius: 8px; overflow: hidden; }
#term-tabs { display: flex; gap: 4px; flex-wrap: wrap; background: #1c1c1c; padding: 6px; align-items: center; font-family: var(--serif); font-size: 14px; color: var(--muted); }
#term-tabs button { font-family: var(--mono); font-size: 13px; padding: 3px 10px; background: #2a2a2a; border: 1px solid #555; }
#term-tabs button.active { background: #3d5a3d; border-color: var(--term-text); }
#term-output { height: 240px; overflow-y: auto; white-space: pre-wrap; padding: 10px; font-size: 14px; }
#term-line { display: flex; padding: 0 10px 10px; font-size: 14px; }
#term-prompt { white-space: pre; }
#term-input { flex: 1; background: transparent; color: var(--term-text); border: none; outline: none; font-family: var(--mono); font-size: 14px; padding: 0 2px; }

#modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; }
#modal .panel { border: 2px solid var(--gold); }

@media (max-width: 760px) {
  #level-body { grid-template-columns: 1fr; }
  h1 { font-size: 34px; }
}

/* ----- compact title on the world and quest screens ----- */
header.compact h1 { font-size: 24px; display: inline-block; margin: 0 12px 0 0; }
header.compact .subtitle { display: none; }
header.compact { text-align: left; padding-right: 150px; }
header.compact .banner { font-size: 11px; }

/* ----- read-aloud buttons ----- */
.say { font-size: 14px; padding: 3px 9px; background: transparent; border: 1px solid var(--line); white-space: nowrap; }
.say:hover { border-color: var(--gold); background: #3a2b48; }
.say.speaking { background: var(--gold); color: #000; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.icon-btn { font-size: 14px; padding: 2px 7px; background: transparent; border: 1px solid var(--line); }
.head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.head-row > p, .head-row > h3 { flex: 1; margin-top: 0; }

/* ----- the world ----- */
.hud { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.hud-left { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.hud-left strong { color: var(--gold); font-size: 19px; }
.hud-right { display: flex; gap: 8px; flex-wrap: wrap; }
#world-wrap { position: relative; border: 2px solid var(--gold); border-radius: 8px; overflow: hidden; background: #17111d; }
#world-canvas { display: block; outline: none; cursor: pointer; image-rendering: pixelated; }
#world-prompt { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(15,10,20,.85); border: 1px solid var(--gold); padding: 4px 14px; border-radius: 14px; font-size: 15px; pointer-events: none; }
#world-help { position: absolute; bottom: 6px; right: 10px; background: rgba(15,10,20,.7); padding: 2px 8px; border-radius: 8px; pointer-events: none; }
#dialog { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; gap: 14px; background: rgba(34, 24, 44, .97); border: 2px solid var(--gold); border-radius: 10px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.6); }
#dialog-portrait { font-size: 54px; line-height: 1; width: 70px; height: 70px; flex: none; display: flex; align-items: center; justify-content: center; background: #17111d; border: 1px solid var(--line); border-radius: 50%; }
#dialog-body { flex: 1; min-width: 0; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#dialog-name { color: var(--gold); font-weight: bold; font-size: 17px; }
#dialog-text { margin: 6px 0 8px; font-size: 18px; min-height: 2.6em; }
#dialog-choices { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
#dialog-choices button { text-align: left; }
#dialog-answer { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
#dialog-input { flex: 1; min-width: 160px; font-family: var(--mono); }
#dialog-next { float: right; }
#journal { position: absolute; inset: 10px; overflow-y: auto; margin: 0; z-index: 2; }

/* ----- Spellbook side panel ----- */
#btn-spellbook { position: fixed; top: 12px; right: 16px; z-index: 20; box-shadow: 0 3px 10px rgba(0,0,0,.5); }
#spellbook-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); z-index: 30; background: #201828; border-left: 2px solid var(--gold); box-shadow: -8px 0 24px rgba(0,0,0,.5); overflow-y: auto; padding: 12px 14px 40px; }
.sb-head { display: flex; justify-content: space-between; align-items: center; }
.sb-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
#sb-search { flex: 1; min-width: 140px; }
#sb-form label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 2px; }
#sb-form input, #sb-form textarea { width: 100%; }
#sb-form textarea { font-family: var(--mono); font-size: 14px; background: #1a1420; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; resize: vertical; }
.spell-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.spell-actions { display: flex; gap: 4px; flex: none; }
.spell.own { border-left-color: var(--green); }
pre.example { white-space: pre-wrap; margin: 6px 0 2px; display: block; }
.region-heading { color: var(--gold); border-bottom: 1px solid var(--line); padding-bottom: 2px; margin-top: 16px; }
@media (min-width: 1000px) { body.sb-open #app { margin-right: 430px; } }

/* ----- Spellbook PDF (browser "Save as PDF") ----- */
@media print {
  @page { margin: 16mm; }
  html, body { background: #fff !important; color: #000; font-size: 12pt; }
  #app, #btn-spellbook, .no-print { display: none !important; }
  #spellbook-panel { display: block !important; position: static; width: auto; box-shadow: none; border: none; background: #fff; padding: 0; overflow: visible; }
  .print-only { display: block; color: #000; }
  h2, h3, .region-heading { color: #000; border-color: #000; }
  .spell { background: #fff; border-left: 4px solid #000; page-break-inside: avoid; box-shadow: none; color: #000; }
  .spell .cmd, .spell .example, code { color: #000; background: #f2f2f2; }
  .spell .short, .spell .mode, .small { color: #444; }
}
