html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0b0a0d;
  font-family: Georgia, 'Times New Roman', serif;
  user-select: none;
}
#wrap { position: absolute; width: 960px; height: 640px; transform-origin: 0 0; }
canvas { display: block; }
#ui { position: absolute; inset: 0; pointer-events: none; }
.hidden { display: none !important; }

.plate {
  background: rgba(28, 20, 14, 0.86);
  border: 2px solid #b08d57;
  color: #f1e4c3;
  padding: 5px 12px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  font-size: 15px;
}
.parchment {
  background: #efe2c4;
  color: #2b1d12;
  border: 4px double #6b4a2b;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.6), inset 0 0 40px rgba(120,80,40,.25);
  pointer-events: auto;
}
.hint { font-size: 12px; color: #7a5e40; font-style: italic; margin-top: 8px; }

/* HUD */
#hud { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; }
#hud { align-items: flex-start; }
#hud-time .clock { font-weight: bold; }
#hud-time .loc { font-size: 12px; font-variant: small-caps; letter-spacing: 1px; color: #c9b48a; }
#hud-event { max-width: 420px; text-align: center; font-size: 13px; }
#hud-event b { color: #f3d27a; display: block; font-variant: small-caps; letter-spacing: 1px; font-size: 14px; }
#hud-event i { color: #d8c49a; }
.neg { color: #e07a6a !important; }
#hud-purse { font-weight: bold; color: #f3d27a; }
#prompt { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); }
#prompt b { color: #f3d27a; }

/* Dialogue */
#dialogue { position: absolute; left: 50px; right: 50px; bottom: 18px; padding: 14px 20px 10px; min-height: 110px; }
#dialogue .speaker { font-weight: bold; font-variant: small-caps; font-size: 18px; color: #6b2a1a; margin-bottom: 6px; letter-spacing: 1px; }
#dialogue .text { font-size: 17px; line-height: 1.45; min-height: 50px; white-space: pre-wrap; }
#dialogue .options { margin: 8px 0 0; padding-left: 26px; }
#dialogue .options li { padding: 2px 6px; cursor: pointer; border-radius: 3px; font-size: 16px; }
#dialogue .options li.sel { background: #6b4a2b; color: #f3e6c8; }
#dialogue .hint { text-align: right; margin-top: 4px; }

/* Panels */
.panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 14px 22px 12px; }
.panel h2 { margin: 0 0 10px; font-variant: small-caps; letter-spacing: 2px; text-align: center; color: #4a2a14; border-bottom: 1px solid #b59a6e; padding-bottom: 6px; }
.panel h3 { margin: 0 0 6px; font-size: 15px; font-variant: small-caps; color: #6b2a1a; }

#inventory { width: 600px; }
#inventory .inv-body { display: flex; gap: 16px; }
#inventory .slots { display: grid; grid-template-columns: repeat(4, 64px); gap: 6px; }
.slot {
  width: 64px; height: 64px; box-sizing: border-box;
  background: #d9c79f; border: 2px solid #9c7b4f; border-radius: 4px;
  position: relative; display: flex; align-items: center; justify-content: center;
  font-size: 32px; cursor: pointer;
}
.slot:hover { border-color: #6b4a2b; }
.slot.sel { border-color: #6b2a1a; background: #e8d6ad; box-shadow: inset 0 0 0 2px #6b2a1a; }
.slot .qty { position: absolute; bottom: 1px; right: 4px; font-size: 13px; font-weight: bold; color: #2b1d12; }
#inventory .details { flex: 1; font-size: 15px; line-height: 1.4; }
#inventory .details .name { font-weight: bold; font-size: 17px; margin-bottom: 4px; }
#inventory .details .icon { font-size: 40px; }
#inventory .details .value { color: #6b4a2b; margin-top: 6px; font-style: italic; }
button {
  font-family: inherit; font-size: 14px; cursor: pointer;
  background: #6b4a2b; color: #f3e6c8; border: 1px solid #3b2414; border-radius: 3px; padding: 4px 12px; margin-top: 8px;
}
button:hover { background: #855c36; }
button:disabled { opacity: .45; cursor: default; }
.pouch { margin-top: 12px; padding-top: 8px; border-top: 1px solid #b59a6e; font-size: 15px; display: flex; justify-content: space-between; }
.pouch .coins span { margin-left: 12px; }

#trade { width: 640px; }
#trade .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
#trade ul { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
#trade li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 3px; cursor: pointer; font-size: 15px; }
#trade li:hover { background: #dccaa0; }
#trade li.disabled { opacity: .45; cursor: default; }
#trade li .ic { font-size: 22px; width: 28px; text-align: center; }
#trade li .nm { flex: 1; }
#trade li .pr { font-weight: bold; color: #6b2a1a; white-space: nowrap; }
#trade li.empty { font-style: italic; color: #8a7050; cursor: default; }

#help table { border-collapse: collapse; font-size: 15px; }
#help td { padding: 3px 14px 3px 0; }
#help td:first-child { font-weight: bold; color: #6b2a1a; }
#help p { max-width: 340px; }

/* Toasts */
#toasts { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.toast {
  background: rgba(28, 20, 14, 0.9); border: 1px solid #b08d57; color: #f1e4c3;
  padding: 6px 12px; border-radius: 4px; font-size: 14px; transition: opacity .5s; max-width: 360px;
}

/* Title */
#title {
  position: absolute; inset: 0; pointer-events: auto;
  background: radial-gradient(ellipse at center, rgba(40,28,18,.75), rgba(8,6,10,.95));
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #f1e4c3;
}
#title h1 { font-size: 64px; margin: 0; letter-spacing: 6px; font-variant: small-caps; color: #f3d27a; text-shadow: 0 3px 0 #3b2414, 0 0 30px rgba(243,210,122,.3); }
#title .sub { font-style: italic; font-size: 20px; margin: 6px 0 28px; color: #d8c49a; }
#title .buttons { display: flex; gap: 14px; }
#title button { font-size: 18px; padding: 8px 22px; }
#title .hint { color: #a08a64; }

#fader { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }

#inventory .inv-summary { font-size: 13px; color: #5a4028; margin: -4px 0 10px; text-align: center; }
#trade .cols.single { grid-template-columns: 1fr; }

#ledger { width: 680px; }
#ledger .tabs { display: flex; gap: 6px; margin-bottom: 10px; }
#ledger .tabs button { margin: 0; background: #b59a6e; color: #2b1d12; }
#ledger .tabs button.on { background: #6b4a2b; color: #f3e6c8; }
#ledger .tab-body { min-height: 280px; max-height: 380px; overflow-y: auto; font-size: 15px; }
#ledger table { width: 100%; border-collapse: collapse; }
#ledger td, #ledger th { padding: 3px 6px; border-bottom: 1px dotted #b59a6e; text-align: left; }
#ledger td.num, #ledger th.num { text-align: right; }
#ledger tr.total td { font-weight: bold; border-top: 2px solid #6b4a2b; }
#ledger .card { display: flex; align-items: center; gap: 12px; padding: 8px; border: 1px solid #c9b48a; border-radius: 4px; margin-bottom: 8px; }
#ledger .card .info { flex: 1; }
#ledger .card .info b { display: block; }
#ledger .card .info span { font-size: 13px; color: #5a4028; }
#ledger .card button { margin: 0; white-space: nowrap; }

#summary { width: 520px; }
#summary .body { font-size: 15px; line-height: 1.45; }
#summary .body p { margin: 6px 0; }
#summary table { width: 100%; border-collapse: collapse; margin: 8px 0; }
#summary td { padding: 2px 6px; }
#summary td.num { text-align: right; }
#summary tr.total td { font-weight: bold; border-top: 2px solid #6b4a2b; }
#summary .go { display: block; margin: 12px auto 0; font-size: 16px; }

#stitch { width: 460px; text-align: center; }
#stitch .instr { font-size: 14px; }
#stitch .track { position: relative; height: 34px; background: #d9c79f; border: 2px solid #6b4a2b; border-radius: 4px; margin: 14px 0; overflow: hidden; }
#stitch .zone { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, #d8b04a, #f3d27a, #d8b04a); opacity: .85; }
#stitch .needle { position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px; background: #2b1d12; box-shadow: 0 0 4px #fff; }
#stitch .stitches { font-size: 22px; letter-spacing: 6px; min-height: 28px; }

/* ---------------- Touch controls (src/touch.js) ---------------- */
#touch { display: none; }
body.touch #touch { display: block; }
body.touch { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
body.touch canvas { touch-action: none; }
body.touch #prompt { pointer-events: auto; cursor: pointer; }
body.touch #title .hint { display: none; }
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 10; touch-action: none; }
#touch .tc-pad {
  position: absolute; left: 0; bottom: 0; width: 45%; height: 60%;
  pointer-events: auto; touch-action: none;
}
#touch .tc-stick-base {
  position: absolute; left: 90px; bottom: 30px; top: auto; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border-radius: 50%; border: 2px solid rgba(176,141,87,.55); background: rgba(28,20,14,.35);
}
#touch .tc-stick-base:not(.active) { top: auto; bottom: 30px; margin: 0 0 0 -60px; }
#touch .tc-stick-base.active { bottom: auto; }
#touch .tc-stick-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(176,141,87,.8); border: 2px solid #f3d27a; box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
#touch .tc-buttons {
  position: absolute; right: 0; bottom: 0; width: 210px; height: 230px; pointer-events: none;
}
#touch .tc-btn {
  position: absolute; pointer-events: auto; touch-action: none; margin: 0; padding: 0;
  border-radius: 50%; border: 2px solid #b08d57; background: rgba(28,20,14,.7); color: #f3d27a;
  font: bold 18px Georgia, serif; width: 50px; height: 50px; box-shadow: 0 2px 8px rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
}
#touch .tc-btn.down { background: rgba(176,141,87,.9); color: #2b1d12; }
#touch .tc-act    { width: 84px; height: 84px; right: 24px; bottom: 34px; font-size: 30px; background: rgba(107,74,43,.85); }
#touch .tc-back   { right: 120px; bottom: 30px; }
#touch .tc-inv    { right: 128px; bottom: 92px; }
#touch .tc-ledger { right: 74px; bottom: 136px; }
#touch .tc-help   { right: 16px; bottom: 136px; width: 40px; height: 40px; font-size: 16px; }
#touch .tc-fs     { right: 16px; top: auto; bottom: 186px; width: 40px; height: 40px; font-size: 18px; }
#touch .tc-rotate {
  display: none; position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--stage-bottom, 60vh) + 8px);
  color: #c9b48a; font: italic 13px Georgia, serif; white-space: nowrap;
}
@media (orientation: portrait) { #touch .tc-rotate { display: block; } }
@media (orientation: landscape) {
  #touch .tc-stick-base:not(.active) { left: 80px; }
  #touch .tc-buttons { height: 240px; }
}

/* Only show what makes sense right now. */
body[data-uimode="title"] #touch { display: none; }
body.touch:not([data-uimode="walk"]) #touch .tc-pad,
body.touch:not([data-uimode="walk"]) #touch .tc-inv,
body.touch:not([data-uimode="walk"]) #touch .tc-ledger,
body.touch:not([data-uimode="walk"]) #touch .tc-help { display: none; }
body[data-uimode="walk"] #touch .tc-back,
body[data-uimode="summary"] #touch .tc-back { display: none; }
