:root {
  /* Yaru: aubergine + white, Ubuntu orange accent */
  --bg: #300a24;          /* aubergine */
  --bg-deep: #2c001e;     /* dark aubergine (terminal, popup) */
  --fg: #f2eef1;
  --dim: #aea79f;         /* warm grey */
  --faint: #5e2750;       /* light aubergine */
  --accent: #e95420;      /* Ubuntu orange */
  --accent-hi: #ff7a45;
  --accent-dk: #c7411a;
  --danger: #ef4444;
  --white: #ffffff;
  --green: var(--white);       /* healthy values */
  --yellow: var(--accent-hi);  /* highlights, stairs, messages */
  --blue: var(--dim);
  --cyan: var(--accent);       /* headings */
  --red: var(--danger);        /* monsters, danger */
  --orange: #aea79f;
  --magenta: #ad7fa8;
  --fs: clamp(9px, 2.35vw, 15px);
  --pt-w: 15ch;            /* portrait width */
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
::selection { background: var(--accent); color: #fff; }
body {
  font-family: "DejaVu Sans Mono", "Menlo", "Consolas", "Courier New", monospace;
  font-size: var(--fs);
  line-height: 1.15;
  min-height: 100vh;
  padding: 10px 12px 16px;
}
/* VT323 (SIL OFL) */
@font-face { font-family: "VT323"; src: url("assets/fonts/VT323.ttf") format("truetype"); font-display: swap; }

/* site banner: white bar, black pixel text */
.site-head {
  background: #fff; color: #000;
  border: 0; border-bottom: 2px solid #000;
  margin: -10px -12px .9em;            /* cancel the body padding: edge to edge, flush with the top */
  padding: .1em .6ch .2em;
  text-align: center;
}
.site-head h1 {
  margin: 0; font-family: "VT323", "DejaVu Sans Mono", monospace; font-weight: normal;
  font-size: clamp(26px, 5.6vw, 48px); line-height: 1.1; letter-spacing: .03em;
}

b { color: #fff; font-weight: normal; }
.y { color: var(--yellow); }

.game {
  display: grid;
  grid-template-columns: var(--pt-w) 12ch minmax(0, 66ch);
  grid-template-areas:
    "portrait stats center"
    "status status status";
  column-gap: 2.5ch;
  justify-content: center;
  margin: 0 auto;
}
.stats  { grid-area: stats; white-space: pre; }
.portrait { grid-area: portrait; position: relative; width: var(--pt-w); aspect-ratio: 1105 / 1091; align-self: start; margin-top: .15em; }
/* the picture sits behind the frame art, inside its opening (about 10.7% in from each side) */
.pt-photo { position: absolute; left: 9.8%; top: 9.8%; width: 80.6%; height: 80.8%; object-fit: cover; object-position: 50% 30%; display: block; }
.pt-frame { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.center { grid-area: center; min-width: 0; }
.status { grid-area: status; white-space: pre; margin-top: 1em; padding-top: .4em; }

.msgs { min-height: 2.4em; white-space: pre-wrap; color: var(--fg); }
.msgs .old { color: var(--dim); }
.msgs .good { color: var(--yellow); }
.msgs .bad { color: var(--red); }
.map { margin: 0; font: inherit; line-height: 1.1; white-space: pre; overflow: hidden; }

.stats .lbl { color: #fff; }
.stats .val { color: var(--green); }
.stats .warn { color: var(--accent-hi); }
.stats .crit { color: var(--danger); font-weight: bold; }
.stats .depth { color: #fff; }

/* map colours */
.w  { color: #c9c2c7; }
.wm { color: #7a5a72; }
.f  { color: #a08a9b; }
.fm { color: #66405c; }
.pl { color: #fff; font-weight: bold; }
.mo { color: var(--danger); font-weight: bold; }
.bs { background: var(--danger); color: #fff; font-weight: bold; }
.dr  { color: var(--accent-hi); font-weight: bold; }   /* closed door  + */
.dro { color: #b8895a; }                               /* open door    ' */
.st { color: var(--yellow); }
.i1 { color: var(--orange); }
.i2 { color: var(--magenta); }
.i3 { color: #e9b96e; }
.i4 { color: var(--white); }

/* boss bar (frame art has a see-through glass strip; the fill sits behind it) */
.bossbar { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .45s ease, margin .45s ease; margin: 0 auto; }
.bossbar.on { grid-template-rows: 1fr; margin-bottom: .6em; }
.bb-inner { overflow: hidden; min-height: 0; }
.bb-box { position: relative; width: min(540px, 92vw); aspect-ratio: 1950 / 510; margin: 0 auto; }
.bb-frame { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* the two visible glass ends; each drains from its outer end toward the skulls */
.bb-seg { position: absolute; top: 54.31%; height: 24.51%; }
.bb-seg.l { left: 16.56%; width: 15.9%; }
.bb-seg.r { left: 67.6%;  width: 15.22%; }
.bb-fill, .bb-trail { position: absolute; inset: 0; transition: clip-path .28s ease-out; }
.bb-fill  { background: linear-gradient(#ff5a5a 0 18%, #d81e3c 18% 62%, #8f0f28 62%); }
.bb-trail { background: #f3d9c4; transition: clip-path .9s ease-out .35s; }  /* lags behind the red, shows recent damage */
.bossbar.snap .bb-fill, .bossbar.snap .bb-trail { transition: none; }
.bb-eyes { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; pointer-events: none; }
.bb-box.hit .bb-eyes { animation: eyes-red .75s ease-out; }   /* eyes flare red on every hit */
@keyframes eyes-red { 0%, 45% { opacity: 1; } 100% { opacity: 0; } }
.bb-box.hit { animation: bb-shake .22s linear; }
.bb-box.hit .bb-fill { filter: brightness(1.6); }
@keyframes bb-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* status bar */
.status .l { color: #fff; }
.status .b { color: var(--blue); }
.status .y { color: var(--yellow); }
.status .g { color: var(--green); }
.status .r { color: var(--red); }

/* terminal: kitty look */
.kitty {
  --k-bg: #0b0b0c; --k-fg: #dddddd; --k-bar: #1b1b1d;
  margin-top: .9em;
  background: var(--k-bg);
  color: var(--k-fg);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2c2c2f;
}
.k-tabbar {
  display: flex; align-items: stretch; gap: .6ch;
  background: var(--k-bar);
  height: 2.1em;
  padding-left: .6ch;
}
.k-logo { height: 1.7em; width: 1.7em; align-self: center; margin-right: .4ch; image-rendering: auto; }
.k-tabs { display: flex; align-items: stretch; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.k-tabs::-webkit-scrollbar { display: none; }
.k-tab {
  display: flex; align-items: center; gap: 1ch; flex: none;
  background: #3b3b3f; color: #c4c4c8;
  padding: 0 2.4ch 0 1.4ch;
  margin-right: -.55em;
  clip-path: polygon(0 0, calc(100% - .9em) 0, 100% 100%, 0 100%);
  white-space: nowrap; cursor: pointer; user-select: none;
}
.k-tab:hover { background: #4a4a4f; }
.k-tab.active { background: var(--accent); color: #0b0b0c; font-weight: bold; cursor: default; position: relative; z-index: 1; }
.k-tab .x { background: none; border: 0; color: inherit; font: inherit; opacity: .6; cursor: pointer; padding: 0 .3ch; line-height: 1; }
.k-tab .x:hover { opacity: 1; }
.k-new { background: none; border: 0; color: #8b8b8f; font: inherit; font-size: 1.15em; cursor: pointer; padding: 0 1.6ch 0 2.2ch; align-self: center; }
.k-new:hover { color: var(--accent-hi); }
.k-hint { margin-left: auto; align-self: center; padding-right: 1.4ch; color: #6d6d70; }
.k-body { padding: .6em 1.2ch .7em; cursor: text; }
.term-out {
  height: 11em;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3d transparent;
}
.term-out div { min-height: 1.15em; }
.term-out .sys { color: var(--accent-hi); }
.term-out .err { color: var(--danger); }
.term-out .dir { color: #6aa8ff; font-weight: bold; }
.term-out .file { color: var(--k-fg); }
.term-out .dim { color: #8b8b8f; }
.term-out a { color: #8ae234; text-decoration: none; border-bottom: 1px dotted #8ae234; }
.term-out a:hover { color: #fff; border-color: #fff; }
.prompt { white-space: pre; }
.prompt .u { color: #8ae234; }
.prompt .p { color: #6aa8ff; }
.prompt .ar { color: var(--accent-hi); }
.term-line { display: flex; gap: 1ch; align-items: baseline; margin-top: .15em; }
.term-line .cmd { position: relative; flex: 1; min-width: 0; }
.mirror { display: block; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1.15em; color: #fff; }
.mirror .ph { color: #55555a; }
.mirror .cur { display: inline-block; min-width: 1ch; background: var(--k-fg); color: #000; }
.mirror.focus .cur { animation: blink 1.1s steps(1) infinite; }
.mirror.blur .cur { background: transparent; color: var(--k-fg); outline: 1px solid var(--k-fg); outline-offset: -1px; }
@keyframes blink { 50% { background: transparent; color: var(--k-fg); } }
.term-line input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; margin: 0;
  font: inherit; font-size: max(16px, 1em); /* 16px stops iOS zoom-on-focus */
  color: transparent; background: transparent; outline: 0;
}

/* discovery popup */
.popups { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.popups:empty { display: none; }
.popups-bar {
  position: absolute; top: 14px; right: 14px; z-index: 200;
  pointer-events: auto;
  background: var(--bg-deep); color: var(--dim);
  border: 1px solid var(--faint); padding: .25em 1.2ch;
  font: inherit; font-size: .85em; cursor: pointer;
}
.popups-bar:hover { color: #fff; border-color: var(--accent); }
/* cascading cards: JS sets top / right / width / z-index per card */
.popup {
  position: absolute;
  pointer-events: auto;
  background: var(--bg-deep);
  border: 1px solid var(--accent);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: pop-in .28s ease-out;
}
.popup.behind { cursor: pointer; }
.popup.behind::after { content: ""; position: absolute; inset: 0; background: rgba(20, 0, 14, .45); }
.popup .p-title {
  flex: none; height: 24px; line-height: 24px; padding: 0 1.2ch;
  background: var(--accent); color: #0b0b0c; font-weight: bold;
  letter-spacing: .1em; font-size: .85em; white-space: nowrap; overflow: hidden;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-10px) scale(.97); } to { opacity: 1; transform: none; } }
.popup .p-img { position: relative; background: #000; flex: 0 1 auto; min-height: 0; display: flex; justify-content: center; border-bottom: 1px solid var(--accent-dk); }
.popup .p-img img { display: block; width: 100%; max-height: 30vh; object-fit: contain; }
.popup .p-close {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  width: 2em; height: 2em; display: grid; place-items: center;
  background: rgba(0,0,0,.65); color: #fff;
  border: 1px solid var(--accent); border-radius: 50%;
  font: inherit; font-size: 1.1em; line-height: 1; cursor: pointer; padding: 0;
}
.popup .p-close:hover { background: var(--accent); color: #000; }
.popup .p-body { padding: .8em 1.2ch .9em; overflow-y: auto; }
.popup .p-item + .p-item { margin-top: .8em; padding-top: .7em; border-top: 1px dashed var(--faint); }
.popup .p-sec { color: var(--dim); font-size: .85em; }
.popup .p-k { color: #fff; margin-top: .15em; }
.popup .p-v { color: var(--fg); overflow-wrap: anywhere; }
.popup .p-v a { color: var(--white); border-bottom: 1px dotted var(--white); text-decoration: none; }

.help { max-width: 110ch; margin: 1.2em auto 0; color: var(--dim); font-size: .85em; text-align: center; }
.link { background: none; border: 0; color: var(--dim); font: inherit; cursor: pointer; padding: 0; }
.link:hover { color: var(--red); }

/* on-screen pad, touch only */
.dpad { display: none; }
@media (pointer: coarse) {
  .dpad { display: grid; grid-template-columns: repeat(3, 3.4em); gap: 4px; margin: 1em auto 0; width: max-content; }
  .dpad button { background: var(--bg-deep); border: 1px solid var(--faint); color: var(--fg); font: inherit; height: 3.2em; border-radius: 4px; touch-action: manipulation; }
  .dpad button:active { background: var(--faint); }
}

@media (max-width: 860px) {
  :root { --pt-w: 19ch; }
  .game {
    grid-template-columns: var(--pt-w) 1fr;
    grid-template-areas: "portrait stats" "center center" "status status";
    row-gap: .8em;
  }
  .stats { display: grid; grid-template-columns: repeat(2, auto); justify-content: start; align-content: start; column-gap: 3ch; }
  .stats .sp { display: none; }
  .stats > div { white-space: pre; }
  .stats .depth { grid-column: 1 / -1; }
  .status { margin-top: 0; }
  .term-out { height: 9em; }
  .popup .p-img img { max-height: 24vh; }
}
