:root {
  --steel: #16181c;
  --brass: #c4a574;
  --brass-d: #8a6a3e;
  --cyan: #3ecfff;
  --ink: #e8e0d4;
  --dim: #9a9184;
  --fail: #e07050;
  --ok: #7dcea0;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  background: radial-gradient(1200px 800px at 50% 20%, #242830, var(--steel));
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}
.shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  padding: 10px;
  gap: 8px;
}
.hud, .dock {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: linear-gradient(#2a2e36, #16181c);
  border: 1px solid #3a3428;
  border-radius: 10px;
  box-shadow: inset 0 1px 0 #4a4030, 0 8px 24px #0008;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: Cinzel, Palatino, serif;
  letter-spacing: 0.12em;
  color: var(--brass);
  text-decoration: none;
}
.brand img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.stat { display: flex; flex-direction: column; min-width: 56px; }
.stat b { font-variant-numeric: tabular-nums; font-size: 1.05rem; color: var(--cyan); }
.stat span { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.grow { flex: 1; min-width: 8px; }
.level-title { font-family: Cinzel, Palatino, serif; flex-shrink: 0; }
.level-title small { display: block; color: var(--dim); font-family: "Source Sans 3", sans-serif; letter-spacing: 0.06em; }
.stage-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  color: var(--dim);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.stage-pick select {
  min-width: 12rem;
  max-width: 18rem;
  text-transform: none;
  letter-spacing: 0.02em;
}
.hud .hall-exit,
.hud .how-btn { flex-shrink: 0; }
#view-wrap {
  position: relative;
  border: 2px solid var(--brass-d);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 0 4px #0c0c0e, inset 0 0 40px #0006;
  background: #0a0c10;
  min-height: 0;
}
#view { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.brief {
  position: absolute; left: 16px; top: 16px; max-width: 280px;
  background: #1c1812ee; border: 1px solid var(--brass-d); border-radius: 10px;
  padding: 10px 12px; pointer-events: none; font-size: 0.85rem; color: var(--ink);
  box-shadow: 0 8px 24px #0008; z-index: 3;
}
.brief b { color: var(--brass); font-family: Cinzel, Palatino, serif; display: block; margin-bottom: 4px; }
.status {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  pointer-events: none; letter-spacing: 0.12em; text-transform: uppercase;
  font-size: 0.8rem; color: var(--brass); z-index: 3;
  background: #16181cee; border: 1px solid var(--brass-d); border-radius: 8px; padding: 4px 10px;
}
.status:empty { display: none; }
.status.fail { color: var(--fail); }
.compass {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px; z-index: 30;
  padding: 8px; background: #16181cee; border: 1px solid var(--brass-d); border-radius: 12px;
  pointer-events: auto;
}
.zoom-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.compass-pad { display: grid; grid-template-columns: 36px 36px 36px; gap: 4px; }
.compass button { width: 36px; height: 36px; padding: 0; font-size: 1rem; pointer-events: auto; }
.zoom-row button { width: 100%; }
.who { color: var(--brass); font-size: 0.85rem; }
button, select, input {
  font: inherit; color: var(--ink);
  background: #2a241c; border: 1px solid var(--brass-d); border-radius: 8px;
  padding: 6px 10px; cursor: pointer;
}
button:hover { border-color: var(--brass); color: var(--brass); }
button.primary { background: #3a3428; border-color: var(--brass); color: var(--brass); }
button.on { background: var(--brass); color: #1c1612; }
a { color: var(--brass); text-decoration: none; }
a.hall-exit, .hud a.hall-exit {
  color: var(--brass); border: 1px solid var(--brass-d); padding: 6px 10px; border-radius: 8px;
}
.modal {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: #0c0c0ef2; z-index: 8; padding: 12px; overflow: auto;
}
.modal[hidden] { display: none !important; }
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: #0c0a08f2; z-index: 50; padding: 16px; overflow: auto;
}
.overlay[hidden] { display: none !important; }
.panel {
  background: linear-gradient(#2a241c, #16141a);
  border: 1px solid var(--brass);
  border-radius: 12px;
  padding: 22px 24px;
  min-width: min(420px, 92vw);
  max-width: 640px;
  width: min(640px, 94vw);
  box-shadow: 0 20px 50px #000a;
  max-height: 92vh;
  overflow: auto;
}
.panel.wide { max-width: 820px; width: min(820px, 96vw); }
.panel h1, .panel h2 { font-family: Cinzel, Palatino, serif; margin: 0 0 8px; color: var(--brass); }
.panel p { margin: 8px 0; color: var(--dim); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.welcome-actions { display: grid; gap: 10px; margin-top: 16px; }
.welcome-actions button { font-size: 1.05rem; padding: 12px 16px; text-align: left; }
.hint { font-size: 0.78rem; color: var(--dim); }
.pad {
  display: grid; grid-template-columns: 36px 36px 36px; gap: 3px;
}
.pad button { width: 44px; height: 36px; padding: 0; }
.pad .n { grid-column: 2; }
.pad .w { grid-column: 1; grid-row: 2; }
.pad .s { grid-column: 2; grid-row: 2; }
.pad .e { grid-column: 3; grid-row: 2; }
.ed-grid {
  display: grid; gap: 3px; margin: 12px 0; justify-content: center;
}
.ed-grid button {
  width: 28px; height: 28px; padding: 0; font-size: 0.72rem;
  font-family: ui-monospace, Consolas, monospace;
}
.ed-grid button.start { outline: 2px solid var(--cyan); }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.list { display: grid; gap: 8px; margin-top: 10px; max-height: 50vh; overflow: auto; }
.list .item {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  border: 1px solid var(--brass-d); border-radius: 8px; padding: 8px 10px;
}
.list .item b { color: var(--brass); }
#file-hint[hidden] { display: none !important; }
@media (max-width: 820px) {
  .shell { grid-template-rows: auto 1fr auto; }
  .compass { transform: translateY(-50%) scale(0.85); transform-origin: right center; }
}
