:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --danger: #e5484d;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a71b3; font-family: var(--font); color: var(--text); }
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 15px; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 18px; border-radius: 12px; cursor: pointer; transition: transform .08s, background .15s, box-shadow .15s;
}
.btn:hover { background: #f0f0f3; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2560d6; }
.btn.danger { color: var(--danger); }
.btn.big { font-size: 18px; padding: 14px 28px; border-radius: 14px; }
.btn.small { font-size: 13px; padding: 6px 12px; border-radius: 9px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ---------- start screen ---------- */
#start {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 50% 35%, #7cc3ec 0%, #3686c8 55%, #24609c 100%); z-index: 20;
}
.start-card {
  background: rgba(255,255,255,0.94); border-radius: 28px; box-shadow: var(--shadow); padding: 32px 28px; width: min(420px, 100%);
  text-align: center; position: relative;
}
#credit { position: absolute; top: 14px; right: 20px; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: 0.2px; opacity: 0.85; }
.start-card h1 { margin: 6px 0 4px; font-size: 44px; letter-spacing: -1px; }
.start-card .sub { margin: 0 0 22px; color: var(--muted); }
.start-btns { display: flex; flex-direction: column; gap: 10px; }
.start-btns .row { display: flex; gap: 10px; }
.start-btns .row .btn { flex: 1; }
#version { position: absolute; left: 14px; bottom: 10px; color: rgba(255,255,255,0.85); font-size: 13px; font-weight: 600; letter-spacing: 0.3px; text-shadow: 0 1px 2px rgba(0,0,0,0.35); }
.version-line { margin: 14px 0 0; text-align: center; font-size: 12px; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(20, 24, 32, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; }
#modal .card {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: calc(100vh - 32px);
  overflow-y: auto; padding: 22px 22px 18px; position: relative;
}
#modal .card.wide { width: min(760px, 100%); }
#modal h2 { margin: 0 0 4px; font-size: 22px; }
#modal h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
#modal p { line-height: 1.5; margin: 6px 0; }
#modal .close { position: absolute; top: 12px; right: 12px; border: 0; background: #f0f0f3; width: 32px; height: 32px; border-radius: 50%; font-size: 16px; cursor: pointer; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.list { display: flex; flex-direction: column; gap: 8px; }
/* the Library: a book's coloured spine, and the page you're reading */
.book-spine { display: inline-block; width: 12px; height: 22px; border-radius: 2px 4px 4px 2px; box-shadow: inset -3px 0 0 rgba(0,0,0,0.18); vertical-align: -4px; }
.book-page { background: #fbf6ea; border: 1px solid #eadfc8; border-radius: 14px; padding: 6px 20px; margin: 10px 0 4px; max-height: 52vh; overflow-y: auto; font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-size: 16px; line-height: 1.6; color: #3a2f22; }
.book-page p { margin: 12px 0; }
.item.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.item {
  display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
}
.item .ic { font-size: 24px; width: 36px; text-align: center; }
.item .info { flex: 1; min-width: 0; }
.item .name { font-weight: 600; }
.item .desc { font-size: 13px; color: var(--muted); }
.tier { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; margin-left: 6px; }
.res { display: flex; gap: 14px; font-weight: 600; flex-wrap: wrap; margin: 6px 0 2px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.choice {
  border: 2px solid var(--line); border-radius: 14px; padding: 8px; cursor: pointer; text-align: center; background: #fff; font: inherit; font-size: 13px;
}
.choice img { width: 100%; image-rendering: pixelated; border-radius: 6px; display: block; margin-bottom: 4px; }
.choice.sel { border-color: var(--accent); background: var(--accent-soft); }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); border-radius: 999px; padding: 5px 12px 5px 6px; cursor: pointer; background: #fff; font: inherit; font-size: 13px; margin: 0 6px 6px 0; }
.chip .sw { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }
.chip.sel { border-color: var(--accent); background: var(--accent-soft); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: center; font-size: 14px; }
kbd { background: #f0f0f3; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 7px; font: 600 12px var(--font); white-space: nowrap; }
ul.rules { padding-left: 20px; margin: 6px 0; line-height: 1.55; }
#mapcanvas { width: 100%; height: auto; border-radius: 14px; display: block; background: #2a71b3; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; margin-top: 10px; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; margin-right: 5px; vertical-align: -1px; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.2); }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 12px; right: 12px; z-index: 10; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#minimap { width: 150px; height: 150px; border-radius: 16px; box-shadow: 0 4px 18px rgba(0,0,0,0.25); border: 3px solid rgba(255,255,255,0.9); cursor: pointer; background: #2a71b3; }
#hudbtns { display: flex; gap: 6px; }
#hudbtns button {
  position: relative; width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,0.88); font-size: 18px; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
#hudbtns button:active { transform: scale(0.94); }
#hudbtns button svg { display: block; margin: auto; }
#saveind { position: absolute; right: 4px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: #34c759; opacity: 0; transition: opacity .3s; }
#saveind.on { opacity: 1; }
#prompt {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: rgba(29,29,31,0.82); color: #fff; padding: 9px 16px;
  border-radius: 12px; font-size: 15px; font-weight: 500; z-index: 10; pointer-events: none; white-space: nowrap;
}
#prompt kbd { background: #fff; color: #1d1d1f; border-color: #fff; margin-right: 6px; }
#toasts { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 25; pointer-events: none; width: min(92vw, 520px); }
/* Town Hall reminders: a note that slides in from the right, below the map and buttons */
#notes { position: fixed; top: 232px; right: 12px; display: flex; flex-direction: column; gap: 8px; z-index: 26; pointer-events: none; width: min(300px, calc(100vw - 24px)); }
.note { pointer-events: auto; position: relative; background: rgba(255,255,255,0.97); color: var(--text); border-radius: 14px; border-left: 5px solid #f7c948; box-shadow: 0 6px 22px rgba(0,0,0,0.2); padding: 10px 34px 11px 14px; animation: note-in .35s cubic-bezier(.2,.8,.3,1); transition: transform .35s ease-in, opacity .35s ease-in; }
.note.out { transform: translateX(calc(100% + 24px)); opacity: 0; }
@keyframes note-in { from { transform: translateX(calc(100% + 24px)); opacity: 0; } to { transform: none; opacity: 1; } }
.note-head { font-size: 12px; font-weight: 600; color: var(--muted); }
.note-text { font-size: 15px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.note-x { position: absolute; top: 4px; right: 6px; border: 0; background: none; font-size: 18px; line-height: 1; padding: 4px; color: var(--muted); cursor: pointer; }
.toast { background: rgba(255,255,255,0.96); color: var(--text); padding: 9px 16px; border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,0.18); font-size: 14px; text-align: center; animation: pop .2s ease-out; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }
#decorbar {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); background: rgba(255,255,255,0.95); border-radius: 16px; box-shadow: var(--shadow);
  padding: 8px; display: flex; gap: 6px; max-width: calc(100vw - 24px); overflow-x: auto; z-index: 11;
}
#decorbar .slot { flex: 0 0 auto; border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 4px 8px; font: 12px var(--font); cursor: pointer; text-align: center; min-width: 64px; }
#decorbar .slot canvas { display: block; margin: 0 auto; }
#decorbar .slot.sel { border-color: var(--accent); background: var(--accent-soft); }
#decorbar .slot.empty { opacity: 0.45; }
#decorbar .note { align-self: center; font-size: 13px; color: var(--muted); padding: 0 8px; white-space: nowrap; }

/* ---------- touch ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 9; }
#stick { position: absolute; left: 24px; bottom: 28px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,0.25); border: 2px solid rgba(255,255,255,0.5); pointer-events: auto; touch-action: none; }
#knob { position: absolute; left: 40px; top: 40px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,0.85); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
#t-action { position: absolute; right: 26px; bottom: 40px; width: 82px; height: 82px; border-radius: 50%; border: 0; background: rgba(47,111,237,0.9); color: #fff; font-size: 34px; pointer-events: auto; box-shadow: 0 4px 16px rgba(0,0,0,0.25); touch-action: manipulation; }
#t-action:active { transform: scale(0.94); }
#t-run { position: absolute; right: 120px; bottom: 34px; width: 58px; height: 58px; border-radius: 50%; border: 0; background: rgba(255,255,255,0.85); font-size: 26px; pointer-events: auto; box-shadow: 0 4px 16px rgba(0,0,0,0.2); touch-action: manipulation; }
#t-run:active { transform: scale(0.94); background: rgba(47,111,237,0.9); }
body.touch #prompt { bottom: 180px; }
body.touch #decorbar { bottom: 180px; }

/* ---------- phase 2 bits ---------- */
canvas.ricon { width: 22px; height: 22px; vertical-align: -6px; flex: 0 0 auto; }
.item canvas.ricon { width: 28px; height: 28px; }
.item .arrow { color: var(--muted); font-weight: 700; }
.item.done { opacity: 0.75; }
.bar { height: 6px; background: #eef0f4; border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.tabs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 10px 0 4px; }
.tabs .chip { padding: 5px 14px; margin: 0; }
.studio { display: flex; gap: 16px; align-items: flex-start; }
.studio-preview { flex: 0 0 auto; text-align: center; background: #f5f5f7; border-radius: 16px; padding: 10px; }
.studio-main { flex: 1; min-width: 0; }
.grid.presets { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.grid.presets .choice { font-size: 12px; }
.grid.presets .choice:disabled { opacity: 1; cursor: default; }
.grid.presets canvas { display: block; margin: 0 auto 2px; }
.row-input { display: flex; gap: 8px; }
.row-input input { flex: 1; min-width: 0; font: inherit; font-size: 15px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; outline: none; }
.row-input input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row-input select { flex: 1; min-width: 0; font: inherit; font-size: 15px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--text); outline: none; }
.row-input select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-head { display: flex; gap: 12px; align-items: center; }
.chat-head canvas { background: #f5f5f7; border-radius: 14px; }
.bubble { background: var(--accent-soft); border-radius: 16px; padding: 14px 16px; margin: 12px 0 4px; font-size: 16px; line-height: 1.5; }
.bag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 10px; }
.bag-cell { border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }
.bag-cell b { font-size: 16px; color: var(--text); }
.pause-top { display: flex; gap: 14px; align-items: center; }
.pause-top canvas { background: #f5f5f7; border-radius: 14px; flex: 0 0 auto; }

@media (max-width: 600px) {
  .studio { flex-direction: column; align-items: stretch; }
  .studio-preview canvas { width: 80px; height: auto; }
  .row-input { flex-direction: column; }
  #minimap { width: 104px; height: 104px; border-radius: 14px; }
  #notes { top: 196px; }
  #hudbtns button { width: 36px; height: 36px; font-size: 16px; }
  #hudbtns { flex-wrap: wrap; justify-content: flex-end; max-width: 130px; }
  #prompt { font-size: 13px; }
  .start-card h1 { font-size: 36px; }
}
