:root {
  --ink: #2A1E14;
  --paper: #FFF8E7;
  --paper-2: #F3E6C8;
  --accent: #3A86FF;
  --brown: #6B4226;
  --reddish: #EA4B22;
  --orange: #FFA41B;
  --shadow: 0 6px 0 rgba(0,0,0,0.18), 0 10px 30px rgba(0,0,0,0.25);
  --font: "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2B3A2E; color: var(--ink); font-family: var(--font); }
#game { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: auto; }
[hidden] { display: none !important; }

.panel {
  background: rgba(255, 248, 231, 0.92);
  border: 3px solid var(--brown);
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}

/* ---------------- HUD ---------------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud-left { position: absolute; top: 12px; left: 12px; padding: 8px 12px; min-width: 190px; font-size: 14px; }
#det-name { font-weight: 800; font-size: 16px; margin-bottom: 4px; color: var(--brown); }
.hud-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; line-height: 1.6; }
.hud-label { color: #7A6450; font-weight: 700; }
#hunches { display: inline-flex; gap: 3px; }
.hunch { width: 14px; height: 14px; border-radius: 50%; border: 3px solid #B8860B; background: #CFEFFF; position: relative; }
.hunch::after { content: ""; position: absolute; width: 3px; height: 7px; background: var(--brown); right: -5px; bottom: -7px; transform: rotate(-40deg); border-radius: 2px; }
.hunch.used { opacity: 0.2; filter: grayscale(1); }
#clue-count, #timer { font-weight: 800; }

#district-toast {
  position: absolute; top: 14px; left: 50%; transform: translate(-50%, -80px);
  padding: 8px 20px; border-radius: 999px; font-weight: 800; font-size: 20px;
  background: var(--paper); border: 3px solid var(--brown); box-shadow: 0 4px 0 rgba(0,0,0,0.2);
  transition: transform 0.35s cubic-bezier(.2,1.4,.4,1), opacity 0.35s; opacity: 0; white-space: nowrap;
}
#district-toast.show { transform: translate(-50%, 0); opacity: 1; }

#minimap-wrap { position: absolute; top: 12px; right: 12px; padding: 6px; }
#minimap { display: block; width: 168px; height: 128px; border-radius: 8px; image-rendering: pixelated; }
#minimap-label { text-align: center; font-size: 11px; font-weight: 700; color: #7A6450; margin-top: 2px; }

#toast {
  position: absolute; left: 50%; top: 70px; transform: translateX(-50%) scale(0.8);
  background: #FFD60A; color: var(--ink); border: 3px solid var(--brown); border-radius: 12px;
  padding: 8px 18px; font-weight: 800; font-size: 17px; opacity: 0; transition: all 0.25s; box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}
#toast.show { opacity: 1; transform: translateX(-50%) scale(1); }

#hint { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); padding: 6px 14px; font-size: 13px; white-space: nowrap; }

/* ---------------- Dialog ---------------- */
#dialog {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(860px, calc(100% - 24px)); min-height: 150px;
  display: flex; gap: 14px; align-items: stretch; padding: 14px;
  background: var(--paper); border: 4px solid var(--brown); border-radius: 18px; box-shadow: var(--shadow);
  cursor: pointer; z-index: 5;
}
#portrait { width: 120px; height: 120px; flex: none; background: radial-gradient(circle at 50% 40%, #FFFFFF, #E8DCC0); border-radius: 14px; border: 3px solid var(--paper-2); align-self: center; }
.dlg-body { flex: 1; display: flex; flex-direction: column; position: relative; }
#dlg-name { font-weight: 900; font-size: 18px; color: var(--brown); margin-bottom: 4px; }
#dlg-text { font-size: 19px; line-height: 1.45; min-height: 56px; }
#dlg-text .hl { background: #FFE58A; padding: 0 3px; border-radius: 4px; font-weight: 800; }
#dlg-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
#dlg-choices button {
  font: inherit; font-size: 16px; font-weight: 800; padding: 8px 14px; border-radius: 12px; cursor: pointer;
  background: #FFFFFF; border: 3px solid var(--brown); color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}
#dlg-choices button:hover, #dlg-choices button:focus-visible { background: #FFE58A; outline: none; }
#dlg-choices button.accuse { background: #FFE0D6; border-color: #B23A1A; }
#dlg-choices button.accuse:hover { background: #FFC2AE; }
#dlg-choices button kbd { display: inline-block; background: var(--paper-2); border-radius: 6px; padding: 0 6px; margin-right: 6px; font-family: inherit; font-size: 13px; }
#dlg-skip {
  position: absolute; top: -4px; right: 0; font: inherit; font-size: 14px; font-weight: 800; cursor: pointer;
  padding: 5px 12px; border-radius: 10px; border: 3px solid var(--brown); background: #FFE58A; color: var(--ink);
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}
#dlg-skip:hover { background: #FFD60A; }
#dlg-skip kbd { font-family: inherit; font-size: 11px; background: rgba(255,255,255,0.7); border-radius: 5px; padding: 0 5px; margin-left: 4px; }
#dlg-more { position: absolute; right: 4px; bottom: 0; font-size: 16px; color: var(--brown); animation: bounce 0.8s infinite; }
@keyframes bounce { 50% { transform: translateY(4px); } }

/* ---------------- Overlays ---------------- */
.overlay { position: absolute; inset: 0; background: rgba(20, 30, 20, 0.55); display: grid; place-items: center; z-index: 6; }
.notebook-page {
  position: relative; width: min(620px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto;
  background: repeating-linear-gradient(#FFFDF4, #FFFDF4 30px, #D6E6F5 31px);
  border-left: 34px solid #E07A5F; border-radius: 10px; padding: 18px 26px 12px; box-shadow: var(--shadow);
}
.notebook-page h2 { margin: 0 0 4px; font-size: 26px; color: var(--brown); }
#nb-case { color: #7A6450; font-weight: 700; margin-bottom: 10px; }
.nb-row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; padding: 6px 0; font-size: 18px; border-bottom: 1px dashed #D8CBB0; }
.nb-row .k { font-weight: 800; color: var(--brown); }
.nb-row .v.unknown { color: #A99A86; font-style: italic; }
.nb-row .v b { background: #FFE58A; padding: 0 4px; border-radius: 4px; }
.chip { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: -2px; border: 2px solid rgba(0,0,0,0.25); margin-right: 4px; }
.nb-sub { margin: 14px 0 4px; font-size: 16px; color: var(--brown); }
.nb-leads { margin: 0; padding-left: 20px; font-size: 16px; line-height: 1.6; }
.nb-tip { background: #E6F4FF; border: 2px solid #9CC7EE; border-radius: 10px; padding: 8px 12px; margin-top: 12px; font-size: 15px; }
.nb-foot { text-align: center; color: #7A6450; font-size: 13px; margin: 14px 0 0; }
.close-x { position: absolute; top: 10px; right: 10px; border: none; background: var(--paper-2); border-radius: 50%; width: 32px; height: 32px; font-size: 16px; cursor: pointer; }

.mag-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.mag-lens {
  width: min(360px, 70vw); height: min(360px, 70vw); border-radius: 50%; overflow: hidden;
  border: 16px solid #B8860B; box-shadow: inset 0 0 40px rgba(255,255,255,0.6), 0 10px 30px rgba(0,0,0,0.4);
  background: radial-gradient(circle at 40% 35%, #F4FBFF, #CFE6F2);
}
.mag-lens canvas { width: 100%; height: 100%; display: block; }
.mag-handle { width: 26px; height: 110px; background: linear-gradient(90deg, #5A3A1A, #8B5A2B, #5A3A1A); border-radius: 10px; margin-top: -10px; transform: rotate(-35deg) translate(70px, -20px); position: absolute; bottom: 60px; right: -50px; z-index: -1; }
#mag-label { margin-top: 12px; font-size: 20px; font-weight: 800; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.5); }
.mag-swatches { display: flex; gap: 16px; margin-top: 8px; background: var(--paper); padding: 6px 14px; border-radius: 999px; border: 3px solid var(--brown); font-weight: 700; font-size: 14px; }
.mag-swatches { flex-wrap: wrap; justify-content: center; max-width: min(620px, 92vw); }
#mag-outfit { display: contents; }
#mag-outfit span { white-space: nowrap; }
#mag-outfit .ok { color: #1E8E3E; }
#mag-outfit .no { color: #C0392B; }
.sw { display: inline-block; width: 26px; height: 14px; border-radius: 8px; vertical-align: -2px; border: 2px solid rgba(0,0,0,0.3); }
.mag-foot { color: #fff; font-size: 13px; margin-top: 8px; text-shadow: 0 1px 0 rgba(0,0,0,0.5); }

/* ---------------- Title / end screens ---------------- */
.screen {
  position: absolute; inset: 0; display: flex; overflow: auto; z-index: 8; padding: 16px;
  background: radial-gradient(circle at 50% 30%, rgba(160, 220, 255, 0.9), rgba(40, 90, 60, 0.95));
}
.title-card {
  width: min(640px, 100%); margin: auto; background: var(--paper); border: 5px solid var(--brown); border-radius: 26px;
  padding: 18px 26px 20px; text-align: center; box-shadow: var(--shadow);
}
#title-art { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto -8px; }
.title-card h1 { margin: 4px 0 2px; font-size: clamp(34px, 7vw, 56px); letter-spacing: 1px; color: var(--brown); text-shadow: 3px 3px 0 #FFD60A; }
.title-card h1 span { color: var(--reddish); }
.tagline { font-size: 17px; margin: 4px 0 14px; }
.reddish { color: var(--reddish); }
.name-row, .seed-row { display: block; font-weight: 700; margin: 8px 0; }
.seed-row { font-size: 13px; color: #7A6450; }
.name-row input, .seed-row input {
  font: inherit; font-weight: 800; padding: 6px 10px; border-radius: 10px; border: 3px solid var(--brown); background: #fff; width: 170px; text-align: center;
}
.seed-row input { width: 100px; font-size: 13px; padding: 3px 6px; border-width: 2px; }
.diff-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.btn {
  font: inherit; font-size: 20px; font-weight: 900; padding: 10px 18px; border-radius: 16px; cursor: pointer;
  background: #FFFFFF; color: var(--ink); border: 4px solid var(--brown); box-shadow: 0 5px 0 var(--brown);
  transition: transform 0.08s; min-width: 150px;
}
.btn small { display: block; font-size: 12px; font-weight: 700; color: #7A6450; }
.btn:hover { transform: translateY(-2px); background: #FFF3C4; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--brown); }
.btn.primary { background: #FFD60A; }
.how { text-align: left; background: #F7EFD9; border-radius: 12px; padding: 8px 14px; margin: 6px 0; }
.how summary { cursor: pointer; font-weight: 800; color: var(--brown); }
.how ol { margin: 8px 0 4px; padding-left: 20px; line-height: 1.55; }
#best-times { font-size: 13px; color: #7A6450; margin: 6px 0 0; }
#end-art { width: 240px; height: 240px; display: block; margin: 0 auto; }
#end-text { font-size: 18px; }
#end-stats { display: grid; grid-template-columns: repeat(2, auto); gap: 4px 20px; justify-content: center; font-size: 16px; margin: 6px 0; }
#end-stats b { color: var(--brown); }
.confetti { position: absolute; width: 10px; height: 14px; top: -20px; z-index: 9; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------------- Touch controls ---------------- */
#touch { position: absolute; inset: auto 0 0 0; height: 0; z-index: 4; }
#touch button {
  position: absolute; border: 3px solid var(--brown); background: rgba(255,248,231,0.85); color: var(--brown);
  font-weight: 900; font-size: 22px; border-radius: 14px; touch-action: none;
}
#touch button.down { background: #FFD60A; }
.dpad { position: absolute; left: 18px; bottom: 18px; width: 170px; height: 170px; }
.dpad button { width: 58px; height: 58px; }
.t-up { left: 56px; top: -170px; } .t-down { left: 56px; top: -58px; }
.t-left { left: 0; top: -114px; } .t-right { left: 112px; top: -114px; }
.tbtns { position: absolute; right: 18px; bottom: 18px; }
.t-big { right: 0; bottom: 0; width: 86px; height: 86px; border-radius: 50% !important; }
.t-mid { right: 96px; bottom: 10px; width: 64px; height: 64px; border-radius: 50% !important; }
.t-small { right: 10px; bottom: 100px; width: 72px; height: 42px; font-size: 15px !important; }
body.touch #hint, body.dlg-open #hint { display: none; }
body.touch #dialog { bottom: 8px; }

#loading { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 24px; font-weight: 800; background: #2B3A2E; z-index: 20; }

@media (max-width: 700px) {
  #hud-left { font-size: 12px; min-width: 150px; }
  #minimap { width: 126px; height: 96px; }
  #hint { display: none; }
  #portrait { width: 80px; height: 80px; }
  #dlg-text { font-size: 16px; }
}
