@font-face {
  font-family: 'Alfa Slab One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/alfa-slab-one.woff2) format('woff2');
}
@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 100%;
  font-display: swap;
  src: url(fonts/archivo.woff2) format('woff2');
}

:root {
  --cream: #f3e4ce;
  --cream-dim: rgba(243, 228, 206, 0.62);
  --ink: #22262e;
  --ink-soft: rgba(22, 26, 31, 0.42);
  --coral: #e2795b;
  --teal: #1c5a5e;
  --joy: 124px;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #e8d9c0;
  color: var(--cream);
  font-family: 'Archivo', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#app { position: fixed; inset: 0; }

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  filter: saturate(0.92) contrast(1.05) brightness(1.01);
}
#stage.dragging { cursor: grabbing; }

#grade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background:
    radial-gradient(130% 100% at 50% 42%, rgba(24,18,12,0) 54%, rgba(24,18,12,0.26) 100%),
    linear-gradient(180deg, rgba(255,214,160,0.04), rgba(255,255,255,0) 38%);
}

#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }

/* ---------------- title ---------------- */
#titleWrap {
  position: fixed;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 30;
  filter: drop-shadow(0 18px 38px rgba(40, 30, 20, 0.18));
}
#titleCard { display: block; width: min(74vw, 800px); height: auto; }

#titleWrap.docking, #titleWrap.docked {
  transform: none;
  filter: drop-shadow(0 4px 10px rgba(35, 26, 18, 0.18));
}
#titleWrap.docked { pointer-events: none; }

/* ---------------- district ---------------- */
#district {
  position: fixed;
  left: 50%;
  top: 15%;
  transform: translate(-50%, -50%);
  width: min(70vw, 470px);
  min-width: 240px;
  opacity: 0;
  pointer-events: none;
  z-index: 25;
  filter: drop-shadow(0 8px 24px rgba(20, 16, 12, 0.28));
}
#district.show { animation: plate 3.2s cubic-bezier(.22,.7,.2,1) forwards; }
#districtCanvas { display: block; width: 100%; height: auto; }
@keyframes plate {
  0%   { opacity: 0; transform: translate(-50%, -44%) scale(0.98); }
  10%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  72%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -52%) scale(1.01); }
}

/* ---------------- hint ---------------- */
#hint {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  gap: 22px;
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(20, 24, 29, 0.34);
  border: 1px solid rgba(243, 228, 206, 0.16);
  color: var(--cream-dim);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: opacity 1.2s ease, transform 1.2s ease;
  z-index: 20;
}
#hint b { color: var(--cream); font-weight: 600; }
#hint.gone { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ---------------- help ---------------- */
#helpBtn {
  position: fixed;
  right: calc(18px + var(--safe-r));
  top: calc(16px + var(--safe-t));
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(243, 228, 206, 0.4);
  background: rgba(22, 26, 31, 0.36);
  color: var(--cream);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(3px);
  z-index: 26;
  transition: background .2s;
}
#helpBtn:active { background: rgba(22, 26, 31, 0.55); }

#helpPanel {
  position: fixed;
  right: calc(18px + var(--safe-r));
  top: calc(64px + var(--safe-t));
  width: min(320px, calc(100vw - 36px));
  padding: 14px 16px 15px;
  border-radius: 14px;
  background: rgba(20, 24, 29, 0.78);
  border: 1px solid rgba(243, 228, 206, 0.18);
  color: var(--cream);
  box-shadow: 0 18px 50px rgba(12, 14, 18, 0.35);
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 27;
  backdrop-filter: blur(6px);
}
#helpPanel.open { opacity: 1; transform: none; pointer-events: auto; }
.help-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px; letter-spacing: 0.24em; color: var(--cream-dim);
  padding-bottom: 9px; margin-bottom: 7px;
  border-bottom: 1px solid rgba(243, 228, 206, 0.14);
}
.help-head button {
  background: none; border: none; color: var(--cream-dim); cursor: pointer;
  width: 26px; height: 26px; display: grid; place-items: center; padding: 0;
}
.help-row {
  display: flex; gap: 12px; justify-content: space-between;
  font-size: 12px; line-height: 1.55; padding: 3px 0;
}
.help-row span:first-child { color: var(--cream-dim); letter-spacing: 0.1em; font-size: 10px; text-transform: uppercase; padding-top: 2px; flex: 0 0 54px; }
.help-row span:last-child { text-align: right; }
.help-foot {
  margin: 10px 0 0; padding-top: 10px;
  border-top: 1px solid rgba(243, 228, 206, 0.14);
  font-size: 11px; line-height: 1.5; color: var(--cream-dim);
}

/* ---------------- joystick ---------------- */
#joyZone {
  position: fixed;
  left: calc(10px + var(--safe-l));
  bottom: calc(28px + var(--safe-b));
  width: calc(var(--joy) * 1.5);
  height: calc(var(--joy) * 1.5);
  display: grid;
  place-items: center;
  touch-action: none;
  z-index: 15;
}
#joyRing {
  position: relative;
  width: var(--joy);
  height: var(--joy);
  border-radius: 50%;
  border: 1.5px solid rgba(243, 228, 206, 0.38);
  background: radial-gradient(circle at 50% 42%, rgba(24, 28, 33, 0.20), rgba(24, 28, 33, 0.40));
  opacity: 0.62;
  transition: opacity .22s ease, border-color .22s ease, background .22s ease;
  box-shadow: inset 0 0 34px rgba(18, 21, 26, 0.28);
}
#joyRing.active {
  opacity: 1;
  border-color: rgba(243, 228, 206, 0.62);
  background: radial-gradient(circle at 50% 42%, rgba(24, 28, 33, 0.26), rgba(24, 28, 33, 0.46));
}
#joyHair {
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  border: 1px solid rgba(243, 228, 206, 0.16);
  pointer-events: none;
}
#joyKnob {
  position: absolute;
  left: 50%; top: 50%;
  width: 41%; height: 41%;
  margin-left: -20.5%; margin-top: -20.5%;
  border-radius: 50%;
  background: rgba(243, 228, 206, 0.18);
  border: 1px solid rgba(243, 228, 206, 0.5);
  box-shadow: 0 5px 14px rgba(15, 18, 22, 0.28), inset 0 1px 2px rgba(255, 250, 236, 0.22);
  transition: background .18s ease, border-color .18s ease;
  will-change: transform;
}
#joyRing.active #joyKnob { background: rgba(243, 228, 206, 0.27); border-color: rgba(243, 228, 206, 0.72); }
.joySheen { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------------- actions ---------------- */
#actions {
  position: fixed;
  right: calc(20px + var(--safe-r));
  bottom: calc(34px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  z-index: 15;
}
.act-btn {
  width: clamp(58px, 6.8vw, 78px);
  height: clamp(58px, 6.8vw, 78px);
  border-radius: 50%;
  border: 1.5px solid rgba(243, 228, 206, 0.42);
  background: rgba(22, 26, 31, 0.34);
  color: var(--cream);
  display: grid;
  place-items: center;
  padding: 0;
  touch-action: none;
  cursor: pointer;
  transition: transform .09s ease, background .16s ease, opacity .16s ease, border-color .16s ease;
  box-shadow: inset 0 0 26px rgba(16, 19, 24, 0.26);
}
.act-btn svg { width: 64%; height: 64%; opacity: 0.92; }
.act-btn.pressed {
  transform: scale(0.94);
  background: rgba(255, 214, 150, 0.66);
  border-color: #fff3dc;
  color: #22313a;
  box-shadow: 0 0 0 7px rgba(255, 214, 150, 0.18), 0 0 24px rgba(255, 200, 120, 0.5);
}
.act-btn.pressed svg { opacity: 1; }

/* ---------------- loading ---------------- */
#loading {
  position: fixed; inset: 0;
  background: #e9dac1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  z-index: 60;
  transition: opacity .9s ease;
  pointer-events: auto;
}
#loading.gone { opacity: 0; pointer-events: none; }
.load-mark {
  font-family: 'Alfa Slab One', serif;
  font-size: clamp(30px, 5vw, 54px);
  color: var(--teal);
  letter-spacing: 0.02em;
}
.load-sub {
  font-size: 10px;
  letter-spacing: 0.34em;
  color: rgba(28, 90, 94, 0.62);
}

@media (max-width: 720px) {
  #hint {
    gap: 10px; font-size: 9px; padding: 8px 12px; letter-spacing: 0.1em;
    bottom: calc(186px + var(--safe-b));
  }
  #actions { right: calc(14px + var(--safe-r)); bottom: calc(28px + var(--safe-b)); }
}
@media (max-height: 520px) and (orientation: landscape) {
  #hint { font-size: 9px; padding: 7px 14px; }
}
