/* The Castle Hall: a dark hall of stone gatehouses, one per castle, in Mind Castle's pixel style.
   Each card wears its own castle's palette on its banner. Pixel borders are box-shadow rings drawn
   outside the box, so bordered things carry margin: var(--px) to keep the ring in their slot. */

@font-face { font-family: "Jacquard"; src: url("fonts/Jacquard12.ttf") format("truetype"); font-display: block; }
@font-face { font-family: "Pixelify"; src: url("fonts/PixelifySans.ttf") format("truetype"); font-weight: 400 700; font-display: block; }

:root {
  --abyss: #0b0a0f;  --night2: #0f0c14;  --night: #16121c;  --dusk: #2a2233;  --well: #0c0a10;
  --stone: #8d8594;  --stone-hi: #a59cad;  --wall: #241e2c;  --wall-hi: #352d40;  --wall-lo: #17131d;
  --paper: #cdb88f;  --paper2: #a8936a;  --paper-hi: #ddcca4;  --ink-soft: #5e4c38;  --bone: #eadfc4;
  --yellow: #d4aa3c;  --blue: #5a4a9a;  --green: #5f9a45;  --red: #b3202c;  --ink: #000;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --px: 4px;
  --type: 1;
  --border: 0 calc(-1 * var(--px)) 0 0 var(--ink), 0 var(--px) 0 0 var(--ink), calc(-1 * var(--px)) 0 0 0 var(--ink), var(--px) 0 0 0 var(--ink);
  --drop: 12px 12px 0 0 rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  min-height: 100vh; display: flex; flex-direction: column;
  background-color: var(--abyss);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='32' shape-rendering='crispEdges'%3E%3Cg fill='%23ffffff' fill-opacity='0.035'%3E%3Crect width='64' height='2'/%3E%3Crect y='16' width='64' height='2'/%3E%3Crect width='2' height='16'/%3E%3Crect x='32' y='16' width='2' height='16'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 64px 32px;
  color: var(--paper); font-family: "Pixelify", ui-monospace, monospace;
  font-size: max(12px, calc(19px * var(--type))); line-height: 1.45;
  -webkit-font-smoothing: none; font-variant-ligatures: none;
  text-wrap: pretty;                 /* every line of copy: no word left alone on the last line */
}
img { image-rendering: pixelated; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 4px dashed var(--yellow); outline-offset: 6px; }
h1, h2, h3, b { text-wrap: balance; }   /* headings and short labels: lines of even length */
h1, h2 { margin: 0; font-family: "Jacquard", "Pixelify", monospace; font-weight: 400; letter-spacing: 1px; line-height: 1.1; }
p { margin: 0; }
.quiet { color: var(--stone); }
.fine { font-size: max(12px, calc(15px * var(--type))); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* --- the hall ------------------------------------------------------------------------------- */
.hall-head { max-width: 1240px; width: 100%; margin: 0 auto; padding: calc(var(--s6) + var(--s2)) var(--s5) var(--s4); }
.hall-head h1 { font-size: max(12px, calc(72px * var(--type))); color: var(--yellow); text-shadow: 5px 5px 0 var(--ink); }
.wordmark { display: inline-flex; align-items: center; gap: var(--s4); }
.wordmark img { width: 75px; height: 75px; image-rendering: pixelated; filter: drop-shadow(5px 5px 0 var(--ink)); flex: none; }
/* the title and its line, centred on the page; the line balanced so it breaks evenly */
.hall-head .intro { max-width: 64ch; margin: 0 auto; text-align: center; }
.hall-head .lead { margin-top: var(--s3); color: var(--stone-hi); text-wrap: balance; }
/* how it works: three numbered stone plaques, spanning the page on desktop, stacked below that */
.how { list-style: none; counter-reset: step; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s4); margin: var(--s5) 0 0; padding: 0; }
@media (max-width: 1024px) { .how { grid-template-columns: minmax(0, 1fr); } }
.how li { counter-increment: step; position: relative; padding: var(--s3) var(--s4) var(--s3) 60px; margin: var(--px);
  background: var(--wall); box-shadow: var(--border), inset -4px -4px 0 0 var(--wall-lo), inset 4px 4px 0 0 var(--wall-hi); }
.how li::before {
  content: counter(step); position: absolute; left: var(--s3); top: var(--s3); width: 34px; height: 34px;
  display: grid; place-items: center; background: var(--yellow); color: var(--night); font-weight: 700; box-shadow: var(--border);
}
.how b { display: block; color: var(--bone); }
.how span { display: block; color: var(--stone-hi); font-size: max(12px, calc(15px * var(--type))); line-height: 1.35; margin-top: 2px; }
.hall-title { font-size: max(12px, calc(40px * var(--type))); color: var(--yellow); text-shadow: 4px 4px 0 var(--ink); margin: var(--s4) 0 var(--s2); }
main { flex: 1; max-width: 1240px; width: 100%; margin: 0 auto; padding: var(--s4) var(--s5) var(--s6); }
.hall {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: calc(var(--s6) + var(--s3)) var(--s5); align-items: stretch; padding-top: var(--s4);
}
.hall > .quiet { grid-column: 1 / -1; }

/* A gatehouse: battlements, a banner in the castle's colours, its painting framed in the gate,
   and a name plate. */
.gate { position: relative; margin: var(--px); margin-top: calc(var(--s4) + var(--px)); display: flex; flex-direction: column; }   /* cards in a row share a height */
.gate .keep {
  position: relative; flex: 1; display: flex; flex-direction: column; background: var(--wall); padding: var(--s3) var(--s3) var(--s4);
  box-shadow: var(--border), inset -4px -4px 0 0 var(--wall-lo), inset 4px 4px 0 0 var(--wall-hi), var(--drop);
}
.gate .keep::before {                                         /* the battlements on top of the wall */
  content: ""; position: absolute; left: calc(-1 * var(--px)); right: calc(-1 * var(--px)); top: calc(-1 * var(--s4) - var(--px));
  height: var(--s4);
  background: repeating-linear-gradient(90deg, var(--ink) 0 4px, var(--wall) 4px 24px, var(--ink) 24px 28px, transparent 28px 40px);
  border-top: 4px solid var(--ink);
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 28px, transparent 28px 40px); mask: repeating-linear-gradient(90deg, #000 0 28px, transparent 28px 40px);
}
.gate .banner {                                               /* hangs from the battlements, in the castle's palette */
  position: absolute; right: var(--s5); top: calc(-1 * var(--s4)); width: 26px; height: 54px; z-index: 2;
  background: linear-gradient(var(--c1) 0 34%, var(--c2) 34% 67%, var(--c3) 67% 100%);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, .6));
}
.gate .art {
  display: block; position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: var(--well);
  box-shadow: inset 0 0 0 4px var(--ink); margin-bottom: var(--s3);
}
.gate .art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gate .art::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 4px var(--ink), inset 0 0 0 8px rgba(0, 0, 0, .35); pointer-events: none; }
.gate .art .no-art {                                          /* no painting: the castle's palette as a night sky */
  position: absolute; inset: 0; display: grid; place-items: center; font-family: "Jacquard", monospace; font-size: 64px;
  color: var(--c3); background: linear-gradient(var(--c1), var(--c2));
}
.gate .plate { padding: 0 var(--s1); flex: 1; display: flex; flex-direction: column; }
.gate h2 { font-size: max(12px, calc(32px * var(--type))); color: var(--bone); text-shadow: 3px 3px 0 var(--ink); overflow-wrap: break-word; }
.gate .topic { color: var(--yellow); font-weight: 700; margin-top: var(--s1); }
.gate .setting { color: var(--stone-hi); font-size: max(12px, calc(15px * var(--type))); margin-top: var(--s2);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.gate .progress { display: flex; align-items: center; gap: var(--s2); margin-top: auto; padding-top: var(--s3); font-size: max(12px, calc(16px * var(--type))); color: var(--stone-hi); }   /* progress and buttons settle at the bottom */
.gate .progress b { color: var(--paper); }
.gate .progress.done b { color: var(--green); }
.gate .actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2) var(--s3); margin-top: var(--s4); }
.gate .actions .btn { flex: 1 1 auto; }
.gate .remove { margin-left: auto; }

/* --- controls --------------------------------------------------------------------------------- */
.btn {
  --bg: var(--blue); --fg: var(--bone);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  background: var(--bg); color: var(--fg); border: 0; cursor: pointer; text-decoration: none;
  font-weight: 700; font-size: max(12px, calc(19px * var(--type))); line-height: 1.2; padding: 10px 20px 14px; margin: var(--px);
  box-shadow: var(--border), inset 0 -6px 0 0 rgba(0, 0, 0, .3), inset 4px 4px 0 0 rgba(255, 255, 255, .4);
  white-space: nowrap; user-select: none; min-height: 44px;
}
.btn:hover { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: var(--border), inset 0 -2px 0 0 rgba(0, 0, 0, .3); }
.btn.gold { --bg: var(--yellow); --fg: var(--night); }
.btn.stone { --bg: #5a5361; }
.btn.red { --bg: var(--red); }
.btn:disabled { --bg: #3a3440; --fg: #7d7486; cursor: not-allowed; filter: none; }
.linkish { background: none; border: 0; cursor: pointer; padding: var(--s2) var(--s1); color: var(--stone-hi); font-weight: 700; font-size: max(12px, calc(16px * var(--type))); min-height: 44px; }
.linkish:hover { color: var(--paper); text-decoration: underline; text-underline-offset: 3px; }
.linkish.danger:hover { color: #e06a6a; }
input[type=password], input[type=text] {
  width: calc(100% - 2 * var(--px)); margin: var(--px); padding: var(--s3) 14px; border: 0;
  background: #e2d3ad; color: var(--night); font-size: max(16px, calc(19px * var(--type)));
  box-shadow: var(--border), inset 4px 4px 0 0 var(--paper2);
}

/* --- empty hall ------------------------------------------------------------------------------- */
.empty { grid-column: 1 / -1; max-width: 640px; padding: var(--s6) 0; }
.empty h2 { font-size: max(12px, calc(40px * var(--type))); color: var(--bone); text-shadow: 3px 3px 0 var(--ink); }
.empty p { margin-top: var(--s3); color: var(--stone-hi); }

/* --- footer and the keeper's door --------------------------------------------------------------- */
.hall-foot { max-width: 1240px; width: 100%; margin: 0 auto; padding: var(--s4) var(--s5) var(--s6); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); border-top: 3px dotted var(--dusk); }

dialog {
  width: min(560px, calc(100% - 32px)); max-height: calc(100vh - 48px); border: 0; padding: var(--s5);
  background: var(--paper); color: var(--night);
  box-shadow: var(--border), inset -4px -4px 0 0 var(--paper2), inset 4px 4px 0 0 var(--paper-hi), var(--drop);
}
dialog::backdrop { background: rgba(0, 0, 0, .72); }
dialog h2 { font-size: max(12px, calc(36px * var(--type))); margin-bottom: var(--s3); padding-right: var(--s6); }
dialog p { margin: var(--s2) 0; }
dialog .linkish { color: var(--ink-soft); }
dialog .linkish:hover { color: var(--night); }
dialog label { display: block; font-weight: 700; margin: var(--s4) var(--s1) var(--s1); }
dialog .hint { font-size: max(12px, calc(15px * var(--type))); color: var(--ink-soft); }
dialog .err { color: #7e1320; font-weight: 700; min-height: 1.4em; margin: var(--s2) var(--s1) 0; }
.keeper-close { position: absolute; top: var(--s3); right: var(--s3); margin: 0; }
.drop {
  display: grid; place-items: center; text-align: center; gap: var(--s2); padding: var(--s6) var(--s4); margin: var(--s4) var(--px) var(--s2);
  background: var(--paper2); box-shadow: var(--border), inset 4px 4px 0 0 #8f7f63; cursor: pointer;
}
.drop.over { background: #b9a57c; outline: 4px dashed var(--blue); outline-offset: 4px; }
.drop b { font-size: max(12px, calc(22px * var(--type))); }
.uploads { margin-top: var(--s3); display: grid; gap: var(--s2); }
.up { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s1) var(--s3); align-items: center; }
.up span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.up small { color: var(--ink-soft); }
.up .meter { grid-column: 1 / -1; height: 12px; margin: var(--px); background: var(--paper2); box-shadow: var(--border); position: relative; }
.up .meter i { position: absolute; inset: 0 auto 0 0; background: var(--green); }
.up.failed small { color: #7e1320; }

/* --- toasts ----------------------------------------------------------------------------------- */
#toasts { position: fixed; right: var(--s4); bottom: var(--s4); display: grid; gap: var(--s2); z-index: 90; max-width: min(420px, calc(100% - 32px)); }
.toast { background: var(--night); color: var(--paper); padding: var(--s3) var(--s4); box-shadow: var(--border), var(--drop); margin: var(--px); font-weight: 700; }
.toast.ok { background: var(--green); color: var(--bone); }
.toast.error { background: var(--red); color: var(--bone); }

/* --- playing ------------------------------------------------------------------------------------ */
body.playing { height: 100vh; height: 100dvh; overflow: hidden; background: #000; background-image: none; }
.play-bar { display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s4); height: 40px; flex: none; background: #07070a; box-shadow: 0 2px 0 0 #1a1a22; }
.play-bar .back { color: var(--yellow); font-weight: 700; text-decoration: none; white-space: nowrap; display: inline-flex; align-items: center; gap: var(--s2); min-height: 40px; }
.play-bar .back img { image-rendering: pixelated; }
.play-bar .back:hover { text-decoration: underline; text-underline-offset: 3px; }
.play-name { color: var(--stone); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.playing iframe { flex: 1; width: 100%; border: 0; display: block; background: #000; }

@media (max-width: 760px) {
  :root { --type: .86; }
  .hall-head { padding: var(--s5) var(--s4) var(--s3); }
  .wordmark img { width: 60px; height: 60px; }
  main, .hall-foot { padding-left: var(--s4); padding-right: var(--s4); }
}
@media (max-width: 480px) {                                  /* phones: the logo and the name stay on one line */
  .hall-head h1.wordmark { font-size: 46px; }
  .wordmark { gap: var(--s3); }
  .wordmark img { width: 45px; height: 45px; filter: drop-shadow(3px 3px 0 var(--ink)); }
}
