:root {
  --paper-top: #fcf6e6;
  --paper-bot: #f2e4c7;
  --ink: #38261d;
  --ink-soft: #644d3e;
  --ink-line: #432e23;
  --sage-wash: #c7ddb0;
  --sage-wash-2: #aecb90;
  --honey-wash: #f6d58b;
  --honey-wash-2: #ebb960;
  --sky-wash: #c8e3f4;
  --sky-wash-2: #a9d0ea;
  --twilight-wash: #4d4e78;
  --twilight-wash-2: #36375d;
  --terracotta: #d98262;
  --paper-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.065'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: #f4ead3;
  font-family: 'Klee One', 'Patrick Hand', 'Georgia', serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}

#canvas-wrap {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}

#canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#canvas-wrap canvas:active {
  cursor: grabbing;
}

/* =========================================================================
   PLAIN, TITLE-FREE WATERCOLOR CURTAIN START (Zero titles / crests / text)
   ========================================================================= */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f4ead2;
  background-image:
    var(--paper-grain),
    radial-gradient(ellipse at 50% 42%, #fcf6e6 0%, #f1e3c4 60%, #e4d1aa 100%);
  transition: opacity 0.7s ease, visibility 0.7s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-minimal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.loading-leaf {
  animation: leafSway 2.4s ease-in-out infinite;
  transform-origin: 18% 76%;
  filter: drop-shadow(1px 2px 0 rgba(56, 38, 29, 0.16));
}

@keyframes leafSway {
  0%, 100% { transform: rotate(-6deg) translateY(0px); }
  50% { transform: rotate(7deg) translateY(-3px); }
}

.loading-bar-track {
  width: 168px;
  height: 8px;
  border-radius: 14px 6px 12px 7px / 6px 10px 5px 11px;
  background: rgba(67, 46, 35, 0.10);
  border: 1.5px solid rgba(67, 46, 35, 0.42);
  overflow: hidden;
  padding: 1px;
}

#loading-bar-fill {
  height: 100%;
  width: 12%;
  border-radius: 10px;
  background: linear-gradient(90deg, #87b471, #d8ae56);
  transition: width 0.25s ease;
}

/* =========================================================================
   SHARED HAND-DRAWN WATERCOLOR PARCHMENT & WOBBLY DIP-PEN BORDER
   (Filter lives on ::before so inner lettering stays 100% razor-crisp!)
   ========================================================================= */
.ghibli-paper {
  position: relative;
  background: transparent;
  color: var(--ink);
}

.ghibli-paper::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background-color: var(--paper-top);
  background-image:
    var(--paper-grain),
    linear-gradient(168deg, rgba(253, 248, 234, 0.94) 0%, rgba(242, 228, 198, 0.92) 100%);
  border: 2px solid var(--ink-line);
  border-radius: 16px 7px 14px 9px / 8px 15px 9px 14px;
  box-shadow:
    3px 4px 0 rgba(56, 38, 29, 0.20),
    inset 0 0 18px rgba(176, 140, 92, 0.16);
  filter: url(#ink-wobble);
  pointer-events: none;
}

.ink-icon {
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* =========================================================================
   TOP-LEFT LOCATION & HOUSE SLIP (Compact, Hand-Lettered, No Title Banner)
   ========================================================================= */
#hud-top-left {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 20;
  padding: 9px 14px 10px;
  max-width: 285px;
  transform: rotate(-0.45deg);
}

.street-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.street-readout {
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 16px;
  letter-spacing: 0.015em;
  color: var(--ink);
  line-height: 1.15;
}

.house-card {
  margin-top: 7px;
}

.house-card.hidden {
  display: none;
}

.ink-divider {
  height: 2px;
  margin-bottom: 6px;
  background: repeating-linear-gradient(
    90deg,
    rgba(67, 46, 35, 0.42) 0px,
    rgba(67, 46, 35, 0.42) 5px,
    transparent 5px,
    transparent 9px
  );
}

.house-card-addr {
  font-family: 'Klee One', serif;
  font-size: 14px;
  font-weight: 600;
  color: #7d3623;
  letter-spacing: 0.01em;
}

.house-card-meta {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 1px;
  line-height: 1.3;
}

/* =========================================================================
   TOP-RIGHT HAND-DRAWN SKETCHBOOK CONTROLS
   ========================================================================= */
#hud-top-right {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.controls-drawer {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.mobile-only {
  display: none;
}

.sketch-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
}

#hud-top-right .sketch-bar:nth-child(1) { transform: rotate(0.32deg); }
#hud-top-right .sketch-bar:nth-child(2) { transform: rotate(-0.28deg); }
#hud-top-right .sketch-bar:nth-child(3) { transform: rotate(0.22deg); }

.sketch-btn {
  position: relative;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--ink);
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 14.5px;
  letter-spacing: 0.015em;
  padding: 3px 9px 4px;
  border-radius: 12px 5px 11px 6px / 6px 11px 5px 10px;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.18s ease, border-color 0.18s ease;
}

.sketch-btn:hover {
  background: rgba(217, 178, 114, 0.24);
  border-color: rgba(67, 46, 35, 0.36);
  transform: translateY(-1px) rotate(-0.4deg);
}

.sketch-btn:active {
  transform: translateY(0px);
}

/* Watercolor brush-dab active washes */
.sketch-btn.active {
  background: linear-gradient(160deg, var(--sage-wash) 0%, var(--sage-wash-2) 100%);
  border: 1.5px solid var(--ink-line);
  color: #22301a;
  box-shadow: 1.5px 2px 0 rgba(56, 38, 29, 0.22);
}

.sketch-btn.tod-morning.active {
  background: linear-gradient(160deg, var(--sky-wash) 0%, var(--sky-wash-2) 100%);
  color: #1e364c;
}

.sketch-btn.tod-golden.active {
  background: linear-gradient(160deg, var(--honey-wash) 0%, var(--honey-wash-2) 100%);
  color: #462a10;
}

.sketch-btn.tod-twilight.active {
  background: linear-gradient(160deg, var(--twilight-wash) 0%, var(--twilight-wash-2) 100%);
  color: #fff6e2;
  border-color: #27223e;
}

.sketch-btn.stamp-btn {
  font-size: 13.5px;
  padding: 3px 8px 4px;
}

.sketch-btn.stamp-btn.active {
  background: linear-gradient(155deg, #f1cf9f 0%, #e4b578 100%);
  color: #3d2415;
}

/* Hand-Drawn Parchment Place Dropdown */
.place-bar {
  gap: 6px;
}

.place-pin {
  margin-left: 2px;
}

.select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#landmark-select {
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 14px;
  color: var(--ink);
  background: rgba(255, 250, 236, 0.72);
  border: 1.5px solid rgba(67, 46, 35, 0.45);
  border-radius: 9px 4px 10px 5px / 5px 9px 4px 9px;
  padding: 3px 10px 4px 9px;
  cursor: pointer;
  max-width: 205px;
  outline: none;
  transition: border-color 0.16s ease, background 0.16s ease;
}

#landmark-select:hover,
#landmark-select:focus {
  background: rgba(255, 252, 242, 0.96);
  border-color: var(--ink-line);
}

/* =========================================================================
   BOTTOM-LEFT HAND-DRAWN WATERCOLOR FIELD MAP (Pinned w/ Washi Tape!)
   ========================================================================= */
#hud-bottom-left {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 20;
  padding: 9px 9px 7px;
  transform: rotate(-0.55deg);
}

.tape {
  position: absolute;
  top: -8px;
  width: 36px;
  height: 13px;
  background: rgba(242, 224, 174, 0.74);
  border: 1px solid rgba(112, 86, 52, 0.28);
  box-shadow: 0 1px 2px rgba(56, 38, 29, 0.14);
  pointer-events: none;
}

.tape-tl {
  left: 14px;
  transform: rotate(-14deg);
}

.tape-tr {
  right: 14px;
  transform: rotate(12deg);
}

#minimap {
  display: block;
  border-radius: 6px 3px 7px 4px;
  border: 1.5px solid rgba(67, 46, 35, 0.58);
  background: #f5ebd2;
  cursor: pointer;
}

.minimap-caption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
  padding: 0 2px;
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 12.5px;
  color: var(--ink-soft);
}

#elev-readout {
  font-family: 'Klee One', serif;
  font-size: 11.5px;
  font-weight: 600;
  color: #4f3524;
  background: rgba(215, 184, 128, 0.34);
  border: 1px solid rgba(67, 46, 35, 0.32);
  padding: 0px 6px 1px;
  border-radius: 8px 4px 7px 5px;
}

/* =========================================================================
   BOTTOM-RIGHT COLLAPSIBLE HAND-LETTERED FIELD MARGIN GUIDE
   ========================================================================= */
#hud-bottom-right {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px 9px 9px;
  transform: rotate(0.45deg);
}

#hud-bottom-right.collapsed {
  padding: 6px;
}

#hud-bottom-right.collapsed .help-body {
  display: none;
}

.help-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border: 1.5px solid rgba(67, 46, 35, 0.42);
  border-radius: 8px 5px 9px 4px;
  background: rgba(246, 224, 176, 0.45);
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.16s ease, transform 0.14s ease;
}

.help-toggle:hover {
  background: rgba(246, 213, 139, 0.78);
  transform: rotate(-4deg);
}

.help-body {
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.55;
}

kbd {
  display: inline-block;
  padding: 0 5px;
  margin: 0 1px;
  font-family: 'Klee One', serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 250, 236, 0.85);
  border: 1.3px solid rgba(67, 46, 35, 0.48);
  border-radius: 5px 3px 6px 3px;
  box-shadow: 1px 1.5px 0 rgba(56, 38, 29, 0.18);
}

/* =========================================================================
   DRIFTING WATERCOLOR CLOUD WHISPER TOAST
   ========================================================================= */
.boundary-toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) rotate(-0.3deg);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 9px;
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 15px;
  color: var(--ink);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.boundary-toast.hidden {
  opacity: 0;
  transform: translate(-50%, -10px) rotate(-0.3deg);
  pointer-events: none;
}

@media (max-width: 820px) {
  #hud-bottom-right { display: none; }
  #minimap { width: 150px; height: 170px; }
  .sketch-bar { flex-wrap: wrap; }
}

/* =========================================================================
   iOS / MOBILE LANDSCAPE FULL-SCREEN TOUCH MODE
   (Active ONLY on touch devices via body.is-mobile — desktop stays untouched!)
   ========================================================================= */
body.is-mobile .mobile-only {
  display: flex;
}

body.is-mobile #hud-bottom-right {
  display: none !important;
}

body.is-mobile #hud-top-left {
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  padding: 6px 11px 7px;
  max-width: 215px;
}

body.is-mobile .street-readout {
  font-size: 13.5px;
}

body.is-mobile .house-card-addr {
  font-size: 12.5px;
}

body.is-mobile .house-card-meta {
  font-size: 10.5px;
}

/* Compact corner hand-drawn parchment toggle buttons */
.mobile-fab {
  appearance: none;
  border: none;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transform: rotate(-0.8deg);
  transition: transform 0.15s ease;
}

.mobile-fab:active {
  transform: scale(0.94);
}

body.is-mobile #hud-top-right {
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  gap: 6px;
}

body.is-mobile .controls-drawer {
  display: none;
  gap: 6px;
}

body.is-mobile .controls-drawer.open {
  display: flex;
}

body.is-mobile .sketch-bar {
  padding: 4px 6px;
  gap: 3px;
}

body.is-mobile .sketch-btn {
  font-size: 13px;
  padding: 4px 8px;
}

body.is-mobile #landmark-select {
  font-size: 13px;
  max-width: 175px;
}

/* Collapsible Watercolor Field Map tucked to bottom-right on mobile so left thumb has the joystick! */
.mobile-map-fab {
  position: fixed;
  bottom: calc(14px + env(safe-area-inset-bottom));
  right: calc(14px + env(safe-area-inset-right));
  z-index: 22;
}

body.is-mobile #hud-bottom-left {
  display: none;
  left: auto;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(64px + env(safe-area-inset-bottom));
  padding: 7px 7px 5px;
  transform: rotate(0.45deg);
}

body.is-mobile #hud-bottom-left.mobile-open {
  display: block;
}

body.is-mobile #minimap {
  width: 146px;
  height: 164px;
}

body.is-mobile .minimap-caption {
  font-size: 10.5px;
}

/* Left-Thumb Hand-Drawn Parchment Virtual Joystick */
.mobile-joystick {
  position: fixed;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 22;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  touch-action: none;
}

.joy-ring {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 53% 47% 51% 49% / 48% 52% 48% 52%;
  background: radial-gradient(circle, rgba(252, 245, 226, 0.42) 0%, rgba(242, 228, 198, 0.24) 72%, rgba(212, 184, 134, 0.36) 100%);
  border: 2px solid rgba(56, 38, 29, 0.62);
  box-shadow:
    2px 3px 0 rgba(56, 38, 29, 0.16),
    inset 0 0 12px rgba(255, 250, 236, 0.35);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mobile-joystick.running .joy-ring {
  border-color: #a8621d;
  box-shadow:
    0 0 0 3px rgba(246, 213, 139, 0.48),
    2px 3px 0 rgba(56, 38, 29, 0.20);
}

.joy-tick {
  position: absolute;
  background: rgba(56, 38, 29, 0.38);
  border-radius: 2px;
  pointer-events: none;
}
.joy-n { top: 7px; left: 50%; width: 2px; height: 7px; transform: translateX(-50%); }
.joy-s { bottom: 7px; left: 50%; width: 2px; height: 7px; transform: translateX(-50%); }
.joy-e { right: 7px; top: 50%; width: 7px; height: 2px; transform: translateY(-50%); }
.joy-w { left: 7px; top: 50%; width: 7px; height: 2px; transform: translateY(-50%); }

.joy-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin-left: -23px;
  margin-top: -23px;
  border-radius: 52% 48% 49% 51% / 50% 48% 52% 50%;
  background: radial-gradient(circle at 38% 34%, #fffaf0 0%, #f1dec0 68%, #dfc395 100%);
  border: 2px solid #38261d;
  box-shadow: 2px 3px 0 rgba(56, 38, 29, 0.25);
  pointer-events: none;
  will-change: transform;
}

.mobile-joystick.running .joy-knob {
  background: radial-gradient(circle at 38% 34%, #fff8df 0%, #f6d58b 70%, #e5b254 100%);
}

.joy-run-badge {
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 11.5px;
  color: #4a2a12;
  background: rgba(246, 213, 139, 0.92);
  border: 1.5px solid #38261d;
  border-radius: 8px 4px 7px 5px;
  padding: 0 7px 1px;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: none;
}

.mobile-joystick.running .joy-run-badge {
  opacity: 1;
  transform: translateY(0);
}

/* Gentle Hand-Drawn Rotate-to-Landscape Hint (Portrait phones only!) */
.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 60;
  align-items: center;
  justify-content: center;
  background: rgba(42, 34, 28, 0.34);
  display: none !important;
}

body.is-mobile:not(.rotate-dismissed) .rotate-hint {
  display: none !important;
}

@media (orientation: portrait) {
  body.is-mobile:not(.rotate-dismissed) .rotate-hint {
    display: flex !important;
  }
}

.rotate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 22px;
  max-width: 260px;
  text-align: center;
}

.rotate-icon {
  animation: tiltPhone 2.4s ease-in-out infinite;
}

@keyframes tiltPhone {
  0%, 100% { transform: rotate(0deg); }
  45%, 65% { transform: rotate(-90deg); }
}

.rotate-text {
  font-family: 'Patrick Hand', 'Klee One', serif;
  font-size: 16px;
  color: var(--ink);
  line-height: 1.25;
}
