/* Colours and fonts used throughout, named once here so they are easy to change. */
:root {
  --ink: #1d1b26;        /* outlines */
  --wood: #2b221b;       /* panel background */
  --wood-dark: #1c1612;  /* wells: slots, log, bars */
  --wood-light: #4a3a2c; /* buttons, borders */
  --edge: #6b5237;
  --gold: #d9b24a;
  --gold-bright: #ffe066;
  --paper: #eadfc4;      /* main text */
  --moss: #b9d28a;       /* headings */
  --serif: "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(ellipse at 40% 40%, #232a22, #100e0c 75%); color: var(--paper);
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
  user-select: none;
}
#app { display: flex; gap: 12px; padding: 12px; align-items: stretch; max-height: 100vh; }
#stage { position: relative; line-height: 0; }
canvas { border: 2px solid var(--ink); border-radius: 6px; cursor: pointer; box-shadow: 0 0 0 2px var(--edge), 0 8px 30px rgba(0, 0, 0, 0.6); }
#view { max-width: 100%; height: auto; }
#mini { position: absolute; top: 12px; right: 12px; box-shadow: 0 0 0 2px var(--gold), 0 4px 14px rgba(0, 0, 0, 0.6); }

/* Drawn icons are made at 80 x 80 and shown smaller, so they stay smooth. */
img.icon, img.ico { pointer-events: none; }
img.icon { width: 40px; height: 40px; }
img.ico { width: 20px; height: 20px; vertical-align: -5px; }

/* Thin scrollbars that match the panel. */
* { scrollbar-width: thin; scrollbar-color: var(--edge) var(--wood-dark); }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--wood-dark); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: var(--edge); border-radius: 4px; }

/* The title that fades away when the page opens. */
#title {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; text-align: center;
  background: #100e0c; pointer-events: none; animation: title-out 2.4s ease-in forwards;
}
#title b { display: block; font: 700 56px var(--serif); letter-spacing: 6px; color: var(--gold-bright); text-shadow: 0 0 30px rgba(255, 200, 80, 0.45); }
#title span { font: italic 18px var(--serif); color: var(--paper); opacity: 0.7; }
@keyframes title-out { 0%, 45% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

#tip {
  position: absolute; pointer-events: none; white-space: nowrap; line-height: 1.4;
  background: rgba(28, 22, 18, 0.95); border: 1px solid var(--gold); border-radius: 4px; padding: 3px 9px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}

/* The special-move button and the tonic timers, under the health bar. */
#status { display: flex; align-items: center; gap: 8px; min-height: 28px; }
#special {
  flex: 0 0 auto; min-width: 118px; padding: 4px 10px; font: 700 13px var(--serif); position: relative; overflow: hidden;
  background: linear-gradient(90deg, #7a5a2a var(--fill, 100%), #2a211a var(--fill, 100%));
}
#special.off { opacity: 0.45; cursor: default; }
#special.wait { color: #b9b2a4; }
#special.armed { color: var(--ink); background: linear-gradient(180deg, #ffe9a8, var(--gold-bright)); animation: armed 0.7s ease-in-out infinite; }
@keyframes armed { 50% { box-shadow: 0 0 12px 2px rgba(255, 224, 102, 0.8); } }
#buffs { font-size: 11px; line-height: 1.25; color: var(--moss); }
#panel button.swap { width: 100%; margin: 2px 0 8px; padding: 6px; }
#panel button.swap small { opacity: 0.7; }
/* Gear tab: scarf colours */
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); background: var(--c, none); cursor: pointer; box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25); }
.swatch.none { background: repeating-linear-gradient(45deg, #3a2f26, #3a2f26 4px, #2a211a 4px, #2a211a 8px); }
.swatch.on { box-shadow: 0 0 0 2px var(--gold-bright); }
#modal h3 { margin-top: 12px; }

/* The right-click menu. */
#menu {
  position: fixed; z-index: 20; min-width: 150px; padding: 4px; line-height: 1.4;
  background: rgba(28, 22, 18, 0.97); border: 1px solid var(--gold); border-radius: 5px;
  box-shadow: 0 0 0 1px var(--ink), 0 6px 18px rgba(0, 0, 0, 0.6);
}
#menu div { padding: 4px 12px; border-radius: 3px; cursor: pointer; white-space: nowrap; }
#menu div:hover { background: var(--edge); color: #fff; }
#menu b { color: var(--gold-bright); font-weight: 600; }

/* ---------- side panel ---------- */
#side {
  position: relative;
  min-height: 0; overflow: hidden;   /* never taller than the window; the item area scrolls instead */
  width: 314px; display: flex; flex-direction: column; gap: 8px; padding: 12px;
  background: linear-gradient(180deg, #33281f, var(--wood) 30%, #241c16);
  border: 2px solid var(--ink); border-radius: 6px;
  box-shadow: 0 0 0 2px var(--edge), inset 0 0 0 1px rgba(255, 220, 150, 0.08), 0 8px 30px rgba(0, 0, 0, 0.6);
}
/* The sound button sits in the corner beside the title. */
#sound { position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; padding: 0; }
#sound.off { opacity: 0.6; }
/* The keep-this-tune button, in the opposite corner: faint when no music is playing, gold once kept. */
#tune { position: absolute; top: 12px; left: 12px; width: 30px; height: 30px; padding: 0; }
#tune.idle { opacity: 0.3; cursor: default; }
#tune.kept { background: linear-gradient(180deg, #ffe9a8, var(--gold-bright)); }
#tune.kept img.ico { filter: brightness(0.25); }
#tune img.ico { vertical-align: middle; }
#sound img.ico { vertical-align: middle; }
h1 {
  margin: 0; padding-bottom: 6px; text-align: center; font: 700 26px var(--serif); letter-spacing: 3px; color: var(--gold-bright);
  text-shadow: 0 2px 0 var(--ink); border-bottom: 1px solid var(--gold);
}
h2 { margin: 0 0 10px; padding-bottom: 6px; font: 700 20px var(--serif); color: var(--gold-bright); border-bottom: 1px solid var(--edge); }
h3 { margin: 12px 0 6px; font: italic 14px var(--serif); color: var(--moss); border-bottom: 1px solid rgba(217, 178, 74, 0.25); }
h3:first-child { margin-top: 0; }

#hpbar { position: relative; height: 24px; background: #3a1414; border: 2px solid var(--ink); border-radius: 5px; overflow: hidden; }
/* The pale bar behind the health bar catches up slowly, showing how much a hit took. */
#hplag { position: absolute; left: 0; top: 0; height: 100%; background: #f3dfae; transition: width 0.9s ease-in 0.3s; }
#hpbar.mid #hpfill { background: linear-gradient(180deg, #f0cf6a, #c9952e 45%, #9a6c1c); }
#hpbar.low #hpfill { background: linear-gradient(180deg, #f07a6a, #c4392e 45%, #8f2018); }
#hpbar.low { animation: hp-low 0.9s ease-in-out infinite; }
@keyframes hp-low { 50% { box-shadow: 0 0 10px 1px rgba(255, 70, 50, 0.8); } }
#hpfill { position: relative; height: 100%; background: linear-gradient(180deg, #86e07a, #4f9f52 45%, #357a3a); transition: width 0.25s; box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3); }
#hptext { position: absolute; inset: 0; text-align: center; line-height: 20px; font-weight: 600; text-shadow: 0 1px 2px #000; }
#coins b { color: var(--gold-bright); font-size: 15px; }

button {
  font: inherit; color: inherit; cursor: pointer; padding: 5px 10px;
  background: linear-gradient(180deg, #5c4936, var(--wood-light)); border: 1px solid var(--ink); border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 230, 170, 0.22), inset 0 -2px 0 rgba(0, 0, 0, 0.3);
  transition: filter 0.1s, transform 0.05s;
}
button:hover { filter: brightness(1.2); }
button:active { transform: translateY(1px); box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.4); }
button.off { opacity: 0.45; }
button.go { background: linear-gradient(180deg, #7a9a4a, #4f6f2f); font: 700 16px var(--serif); padding: 7px 22px; }
#tabs { display: flex; gap: 3px; border-bottom: 2px solid var(--edge); }
#tabs button { flex: 1; padding: 6px 2px 5px; border-radius: 5px 5px 0 0; border-bottom: none; font-size: 13px; white-space: nowrap; }
#tabs button.on { background: linear-gradient(180deg, #8a6f3a, #5c4a2a); color: var(--gold-bright); box-shadow: inset 0 2px 0 var(--gold); }
#tabs img.ico { width: 20px; margin-right: 1px; }

#side > * { flex-shrink: 0; }   /* only the item area gives up room */
#panel { flex: 1 1 0; min-height: 150px; overflow-y: auto; padding-right: 2px; }   /* long lists scroll inside the panel */
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
/* The pack: five columns of square slots, all one size. ui.js works out --slot as the
   biggest square that lets every row fit, so slots shrink together and never flatten. */
#panel.pack { display: flex; flex-direction: column; overflow: hidden; }
.packhead { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; font-size: 12px; }
.packhead span { opacity: 0.65; }
.packhead b { font: 700 14px var(--serif); color: var(--gold-bright); }
.grid.pack { flex: 0 0 auto; grid-template-columns: repeat(5, var(--slot, 54px)); grid-auto-rows: var(--slot, 54px); justify-content: center; }
.grid.pack .slot { aspect-ratio: auto; min-height: 0; min-width: 0; }
.grid.pack img.icon { width: min(40px, calc(var(--slot, 54px) - 16px)); height: min(40px, calc(var(--slot, 54px) - 16px)); }
.grid.pack.small .label { display: none; }   /* too small for names: hover shows them instead */
.grid.pack.small img.icon { width: calc(var(--slot) - 8px); height: calc(var(--slot) - 8px); }
.grid.keys { grid-template-columns: repeat(6, 1fr); margin-bottom: 4px; }
.grid.keys .slot { min-width: 0; padding: 2px 0; }
.grid.keys .label { display: none; }
.grid.keys img.icon { width: 32px; height: 32px; }
.grid.wide { grid-template-columns: repeat(6, 54px); min-height: 58px; }
.slot {
  position: relative; aspect-ratio: 1; min-width: 50px; cursor: pointer; overflow: hidden;
  background: radial-gradient(circle at 50% 38%, #3a2f26, var(--wood-dark) 75%);
  border: 2px solid var(--ink); border-radius: 5px; box-shadow: inset 0 0 0 1px var(--tint, #4a3a2c);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: transform 0.08s, filter 0.08s;
}
.slot:not(.empty):hover { filter: brightness(1.3); transform: translateY(-1px); }
.slot.empty { cursor: default; box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5); background: var(--wood-dark); }
.slot.rare { box-shadow: inset 0 0 0 1px var(--gold-bright), inset 0 0 10px rgba(255, 224, 102, 0.35); }
.slot.resting img { filter: grayscale(1) brightness(0.55); }
.slot .label { width: 100%; font-size: 8px; line-height: 1; height: 8px; text-align: center; opacity: 0.85; padding: 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .count { position: absolute; top: 0; right: 3px; font-size: 11px; font-weight: 700; color: var(--gold-bright); text-shadow: 0 1px 0 #000, 1px 0 0 #000, -1px 0 0 #000; }
.hint { margin: 8px 0 0; font-size: 12px; opacity: 0.7; }
.hint.top { margin: 0 0 10px; }
.hint.none { margin: 0; grid-column: 1 / -1; }
#iteminfo { flex: 0 0 auto; min-height: 34px; font-size: 12px; color: var(--moss); }

.skill { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 0 6px; margin-bottom: 8px; }
.skill b { font: 700 17px var(--serif); color: var(--gold-bright); }
.skill small { grid-column: 2 / -1; font-size: 11px; opacity: 0.6; }
.skill img { grid-row: span 3; align-self: start; margin-top: 1px; }
.xpbar { grid-column: 2 / -1; height: 6px; background: var(--wood-dark); border: 1px solid var(--ink); border-radius: 3px; overflow: hidden; }
.xpbar div { height: 100%; background: linear-gradient(180deg, #f6dc7a, #c9962a); }

/* Gear rows. "#panel .gear" because the panel itself also carries the class "gear" on that tab. */
#panel .gear { display: grid; grid-template-columns: 70px 54px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }

/* Quests tab */
.quest {
  background: var(--wood-dark); border: 1px solid var(--ink); border-left: 4px solid var(--edge); border-radius: 4px;
  padding: 6px 9px; margin-bottom: 5px; cursor: pointer; transition: filter 0.1s, transform 0.1s;
}
.quest:hover { filter: brightness(1.3); transform: translateX(2px); }
.quest b { font: 700 15px var(--serif); color: var(--paper); }
.quest i { font: 11px/1 system-ui, sans-serif; font-style: normal; text-transform: uppercase; letter-spacing: 1px; opacity: 0.55; margin-right: 7px; }
.quest small { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; margin-top: 3px; font-size: 12px; line-height: 1.35; opacity: 0.8; }
.quest.active { border-left-color: var(--gold-bright); box-shadow: 0 0 10px rgba(255, 224, 102, 0.18); }
.quest.active b { color: var(--gold-bright); }
.quest.ready { border-left-color: #7dff8a; }
.quest.ready small { color: #b9f2a8; }
.quest.locked b { opacity: 0.7; }
.quest.done { padding: 3px 9px; background: none; border-color: transparent; border-left-color: #4f7a45; }
.quest.done b { font-size: 14px; opacity: 0.6; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chips em { font: 11px system-ui, sans-serif; padding: 1px 7px; border-radius: 9px; background: #3a1f1c; border: 1px solid #7a3a32; color: #ffb4a6; }
#panel h3 b { float: right; font: 12px system-ui, sans-serif; opacity: 0.6; letter-spacing: 0; }

/* Messages sit see-through over the bottom-left of the map. Clicks go straight through
   to the map; only the typing box takes them. While you type, the box grows, turns
   solid and can be scrolled back. */
#talk {
  position: absolute; left: 10px; bottom: 10px; z-index: 1; width: min(46%, 400px);
  display: flex; flex-direction: column; gap: 4px; line-height: 1.4; pointer-events: none;
}
#log {
  max-height: 124px; overflow: hidden; font-size: 12px; padding: 6px 8px; overflow-wrap: anywhere;
  background: rgba(16, 14, 12, 0.45); border: 1px solid rgba(0, 0, 0, 0.5); border-radius: 4px; text-shadow: 0 1px 2px #000;
  transition: background 0.15s;
}
#log:empty { display: none; }
#talk:focus-within #log { max-height: min(300px, 60vh); overflow-y: auto; background: rgba(16, 14, 12, 0.88); pointer-events: auto; user-select: text; }
#log div { margin-bottom: 3px; opacity: 0.8; }
#log div:last-child { margin-bottom: 0; }
#log div:last-child { color: #fff; opacity: 1; }

#foot { display: flex; align-items: flex-end; gap: 8px; }
#savestate { flex: 1; font-size: 12px; opacity: 0.7; }
#savestate.bad { color: #ff9a8a; opacity: 1; }
#savebar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
#savebar button { font-size: 12px; padding: 4px 2px; }

/* ---------- windows ---------- */
#modal {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 410px; max-width: 94%; max-height: 90%; overflow-y: auto; line-height: 1.45; padding: 16px;
  background: linear-gradient(180deg, #35291f, var(--wood)); border: 2px solid var(--ink); border-radius: 8px;
  box-shadow: 0 0 0 2px var(--gold), inset 0 0 0 1px rgba(255, 220, 150, 0.12), 0 14px 50px rgba(0, 0, 0, 0.75);
  animation: window-in 0.18s ease-out;
}
@keyframes window-in { from { opacity: 0; transform: translate(-50%, -46%); } }
@keyframes page-in { from { opacity: 0; transform: translateY(5px); } }
#modal p { margin: 0 0 10px; }
#modal .page { animation: page-in 0.3s ease-out; }
#modal .speech, #modal .narr { font: 17px/1.5 var(--serif); }
#modal .narr { font-style: italic; color: #d9cfb4; text-align: center; padding: 4px 8px; }
#modal .narr::before, #modal .narr::after {   /* an ornamental rule above and below narration */
  content: ""; display: block; height: 9px; margin: 2px auto 8px; width: 60%;
  background: linear-gradient(90deg, transparent, var(--gold) 30%, var(--gold) 70%, transparent) center / 100% 1px no-repeat,
              radial-gradient(circle, var(--gold) 3px, transparent 3.5px) center / 9px 9px no-repeat;
}
#modal .narr::after { margin: 8px auto 2px; }
#modal .talk { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: start; }
#modal .portrait {
  width: 96px; height: 96px; border: 2px solid var(--ink); border-radius: 6px; box-shadow: 0 0 0 2px var(--gold);
  background: radial-gradient(circle at 50% 35%, #c9b88c, #6e5a3c);
}
#modal .prize {
  background: var(--wood-dark); border: 1px solid var(--gold-bright); border-radius: 5px; padding: 9px 11px;
  color: var(--gold-bright); font: 700 16px var(--serif); box-shadow: 0 0 16px rgba(255, 224, 102, 0.25);
}
#modal .pages { opacity: 0.5; line-height: 30px; }
#modal .reqs { background: var(--wood-dark); border: 1px solid var(--ink); border-radius: 5px; padding: 8px 10px; margin-bottom: 10px; }
#modal .reqs span { font: italic 14px var(--serif); color: var(--moss); }
#modal .reqs p { margin: 4px 0 0; }
#modal .reqs .ok { color: #9aff9a; }
#modal .reqs .no { color: #ff9a8a; }
/* A tick or a cross drawn with borders, so no special characters are needed. */
.mark { display: inline-block; width: 12px; height: 12px; margin-right: 8px; position: relative; vertical-align: -1px; }
.ok .mark::before { content: ""; position: absolute; left: 3px; top: -1px; width: 5px; height: 10px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(40deg); }
.no .mark::before, .no .mark::after { content: ""; position: absolute; left: 5px; top: 0; width: 2px; height: 12px; background: currentColor; transform: rotate(45deg); }
.no .mark::after { transform: rotate(-45deg); }
#modal .entry { opacity: 0.55; padding-left: 10px; border-left: 2px solid var(--edge); font-family: var(--serif); font-size: 15px; }
#modal .entry.now { opacity: 1; border-left-color: var(--gold-bright); }
#modal .row { display: grid; grid-template-columns: 54px 1fr auto; align-items: center; gap: 10px; margin-bottom: 6px; }
#modal .row.locked { opacity: 0.5; }
/* A forge row the story is asking for right now. */
#modal .row.story {
  padding: 6px; margin-bottom: 10px; background: var(--wood-dark); border: 1px solid var(--gold-bright); border-radius: 5px;
  box-shadow: 0 0 16px rgba(255, 224, 102, 0.25);
}
#modal .row.story em { display: block; font: italic 13px var(--serif); color: var(--gold-bright); }
#modal .row .slot { cursor: default; }
#modal .row .slot .label { display: none; }
#modal .row small { display: block; font-size: 11px; opacity: 0.65; }
#modal .close { margin-top: 10px; float: right; }

@media (max-width: 900px) {
  #app { flex-direction: column; }
  #app { max-height: none; }
  #side { width: auto; overflow: visible; }
  #panel { flex: 0 0 auto; min-height: 260px; max-height: 46vh; }
  #panel.pack { display: block; overflow-y: auto; }
  .grid.pack { grid-auto-rows: auto; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); }
  .grid.pack .label { display: block !important; }
  .grid.pack .slot { aspect-ratio: 1; }
  .grid.pack img.icon { width: 40px !important; height: 40px !important; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); }
}

/* ---------- playing online (see js/net.js) ---------- */
/* The chat box and Log out button only exist online; the four save buttons only offline. */
#chat, #logout { display: none; }
body.online #chat { display: block; }
/* Log out is small and tucked in the corner, and needs a second click ("Sure?"). */
body.online #logout { display: block; flex: none; font-size: 11px; padding: 1px 7px; opacity: 0.55; }
body.online #logout:hover { opacity: 1; }
#logout.sure { opacity: 1; background: linear-gradient(180deg, #b0483c, #7a2a22); color: #fff; }
body.online #savebar { display: none; }
#chatbox, #login input {
  width: 100%; padding: 5px 8px; font: inherit; color: var(--paper); user-select: text;
  background: var(--wood-dark); border: 1px solid var(--ink); border-radius: 4px;
}
#chatbox:focus, #login input:focus { outline: 1px solid var(--gold); }
#chatbox { pointer-events: auto; background: rgba(16, 14, 12, 0.5); border-color: rgba(0, 0, 0, 0.5); }
#chatbox::placeholder { color: var(--paper); opacity: 0.6; }
#chatbox:focus { background: rgba(16, 14, 12, 0.92); }
#log b.who { color: #cfe8ff; }
#log b.who.me { color: var(--gold-bright); }   /* your own lines */
#log i { color: var(--moss); }

/* The login box, over the map. */
#login { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; line-height: 1.4; background: rgba(16, 14, 12, 0.6); border-radius: 6px; }
#login[hidden] { display: none; }
#loginform {
  width: min(320px, 90%); padding: 18px 20px; text-align: center;
  background: var(--wood); border: 2px solid var(--ink); border-radius: 8px; box-shadow: 0 0 0 2px var(--gold), 0 10px 40px rgba(0, 0, 0, 0.7);
}
#loginform > b { display: block; font: 700 30px var(--serif); letter-spacing: 3px; color: var(--gold-bright); }
#loginnote { min-height: 1.4em; margin: 8px 0; color: #ffd9a0; }
#loginfields { display: grid; gap: 8px; text-align: left; }
#loginfields[hidden] { display: none; }
#loginfields label { font-size: 12px; color: var(--moss); }
#loginfields button { width: 100%; }
#loginhelp a { color: var(--gold-bright); }
