@font-face {
  font-family: Montserrat;
  src: url('../assets/fonts/montserrat.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: Montserrat, system-ui, sans-serif;
  background: #101b31;
  color: #fff9e5;
  --ink: #173e38;
  --panel: rgba(19, 29, 48, .91);
  --line: #c3dbc04f;
  --mint: #b9ffdb;
  --gold: #f4d288;
  --shadow: 0 8px 25px #1a39285c;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
button, select, input { font: inherit; }
button, select, a { -webkit-tap-highlight-color: transparent; }
button, select { cursor: pointer; }
button { color: inherit; }
a { color: inherit; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid #d7ffdf; outline-offset: 3px; }
[hidden] { display: none !important; }
#play { position: fixed; inset: 0; }
#field { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#field:active { cursor: grabbing; }
#field:focus { outline: none; }
.hud { position: absolute; }
body:not([data-state="playing"]) #play { visibility: hidden; }

.top {
  top: max(22px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  right: max(24px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
.place, .top-actions { pointer-events: auto; display: flex; gap: 10px; align-items: center; }
.place {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 20px 10px 11px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.place h1 { font-size: clamp(1rem, 2vw, 1.44rem); margin: 2px 0 0; line-height: 1.05; letter-spacing: -.055em; font-weight: 800; }
.place-game { font-size: .69rem; letter-spacing: .13em; font-weight: 750; color: var(--gold); text-transform: uppercase; }
.compass { width: 38px; height: 38px; flex: none; display: grid; place-items: center; background: #305c4c; border-radius: 50%; position: relative; }
.compass::before { content: ''; width: 22px; height: 22px; border: 1.5px solid var(--mint); border-radius: 50%; }
.compass::after { content: ''; width: 9px; height: 9px; transform: rotate(45deg); background: var(--mint); position: absolute; }
.top-actions { background: var(--panel); border: 1px solid var(--line); border-radius: 15px; padding: 5px; box-shadow: var(--shadow); }
.language select, .icon-button { background: #284d43; border: 1px solid #b5d4be45; border-radius: 10px; color: #f9f8e4; height: 40px; }
.language select { padding-inline: 10px 4px; font-size: .76rem; font-weight: 680; }
.icon-button { min-width: 42px; font-size: 1rem; }
.icon-button:hover, .zoom button:hover { background: #407363; }

.quest {
  top: calc(max(22px, env(safe-area-inset-top)) + 86px);
  left: max(24px, env(safe-area-inset-left));
  max-width: min(310px, calc(100vw - 48px));
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: start;
  gap: 11px;
  padding: 13px 17px 13px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid #e9bf69;
  border-radius: 15px;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.quest-symbol { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; background: #574a2d; }
.quest-symbol i { width: 11px; height: 11px; border: 2px solid var(--gold); transform: rotate(45deg); }
.quest h2 { margin: 0; font-size: .92rem; color: #fff2c9; letter-spacing: -.038em; font-weight: 800; }
.quest p { margin: 5px 0 0; font-size: .76rem; line-height: 1.44; color: #e0e6ce; }
.quest-progress { display: flex; gap: 6px; color: #ded8d4; align-items: baseline; margin-top: 8px; font-size: .70rem; }
#repair-count { color: #ead2fb; font-weight: 800; font-variant-numeric: tabular-nums; }

.zoom {
  top: calc(max(22px, env(safe-area-inset-top)) + 76px);
  right: max(24px, env(safe-area-inset-right));
  display: grid;
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.zoom button { border: 0; border-radius: 8px; background: #284d43; width: 36px; height: 36px; font-size: 1.18rem; }
.waypoints { pointer-events: none; position: absolute; inset: 0; overflow: hidden; }
.waypoint {
  position: absolute;
  transform: translate(-50%,-100%);
  border-radius: 9px;
  background: #243e34e8;
  border: 1px solid #e2d6aaba;
  color: #fff2cf;
  padding: 5px 8px;
  font-size: .67rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 3px 12px #28453644;
}
.waypoint::after { content: ''; position: absolute; left: calc(50% - 3px); bottom: -4px; width: 6px; height: 6px; rotate: 45deg; background: #e8c177; }
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(max(22px, env(safe-area-inset-bottom)) + 89px);
  transform: translateX(-50%);
  margin: 0;
  background: #183e32e8;
  border: 1px solid #beebbd99;
  color: #eeffce;
  border-radius: 10px;
  padding: 9px 13px;
  max-width: calc(100vw - 36px);
  text-align: center;
  font-size: .79rem;
  font-weight: 720;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.bottom {
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
}
.field-controls { display: flex; gap: 12px; padding: 6px 9px; font-size: .67rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); white-space: nowrap; }
.field-controls span { display: inline-flex; align-items: center; gap: 4px; }
kbd { font: inherit; font-weight: 830; background: #bbd8b8; color: #243a32; padding: 2px 5px; border-radius: 4px; white-space: nowrap; }
.actions { right: max(24px, env(safe-area-inset-right)); bottom: max(26px, env(safe-area-inset-bottom)); display: flex; align-items: end; gap: 8px; }
.actions button { min-height: 44px; border: 1px solid #f6e4b5aa; border-radius: 13px; background: var(--panel); padding: 8px 12px; font-weight: 800; font-size: .76rem; }
.actions button:disabled { opacity: .44; cursor: default; }
.actions button:enabled:hover, .actions button:enabled:active { background: #376751; }
.interact { display: flex; align-items: center; gap: 6px; }
.touch { display: none; }
body[data-touch="true"] .touch { display: grid; place-items: center; }
body[data-touch="true"] .field-controls, body[data-touch="true"] .interact kbd { display: none; }
.joystick {
  width: 94px;
  height: 94px;
  border-radius: 50%;
  background: #203e3785;
  border: 1px solid #e8f5cfaa;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: max(24px, env(safe-area-inset-left));
  touch-action: none;
}
.joystick span {
  width: 40px; height: 40px; border-radius: 50%;
  background: #d6eae0be; border: 2px solid #f6ffe7; pointer-events: none;
  transform: translate(var(--stick-x, 0px),var(--stick-y, 0px));
}
.load-status { position: absolute; top: 50%; left: 50%; width: min(320px, 86vw); transform: translate(-50%,-50%); text-align: center; font-weight: 700; }
.load-status a { color: var(--mint); }
dialog {
  max-width: min(470px, calc(100% - 32px));
  width: 100%;
  max-height: calc(100% - 24px);
  padding: 24px;
  border-radius: 18px;
  border: 1px solid #c5dbc07c;
  color: #fcf5d9;
  background: #1d293f;
  box-shadow: 0 16px 65px #142c20a8;
}
dialog::backdrop { background: #132d28aa; }
.dialog-tag { color: var(--gold); font-size: .72rem; font-weight: 760; }
dialog h2 { font-size: clamp(1.3rem,3vw,1.82rem); letter-spacing: -.05em; margin: 6px 0; }
dialog p { color: #e9e9d0; font-size: .86rem; line-height: 1.6; margin: 8px 0 15px; }
dialog button { min-height: 41px; border: 1px solid #e1f3bb97; border-radius: 9px; padding: 7px 12px; font-size: .75rem; font-weight: 800; }
dialog button:hover { filter: brightness(1.09); }
.primary { background: #d8f3a9; color: #213e2d; }
.secondary { background: #375a4c; }
.slider { display: grid; gap: 6px; font-size: .75rem; color: #fff0ca; margin-block: 10px 15px; }
.slider input { width: 100%; accent-color: #c9edb0; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }

@media (pointer: coarse) {
  .touch { display: grid; place-items: center; }
  .field-controls, .interact kbd { display: none; }
}
@media (max-width: 650px), (max-height: 470px) {
  .top { top: max(9px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); }
  .place { padding: 5px 10px 5px 5px; border-radius: 12px; gap: 6px; }
  .place-game { font-size: .53rem; letter-spacing: .09em; }
  .compass { width: 32px; height: 32px; }
  .compass::before { width: 17px; height: 17px; }
  .top-actions { gap: 4px; border-radius: 12px; padding: 3px; }
  .language select, .icon-button { height: 36px; min-width: 36px; }
  .language select { max-width: 108px; padding-inline: 6px 3px; }
  .quest { top: calc(max(9px,env(safe-area-inset-top)) + 54px); left: max(10px,env(safe-area-inset-left)); max-width: 224px; grid-template-columns: 24px 1fr; padding: 7px 9px; gap: 7px; border-radius: 10px; }
  .quest-symbol { width: 24px; height: 24px; border-radius: 7px; }
  .quest h2 { font-size: .76rem; }
  .quest p { font-size: .66rem; }
  .quest-progress { margin-top: 4px; font-size: .64rem; }
  .zoom { top: calc(max(9px,env(safe-area-inset-top)) + 53px); right: max(10px,env(safe-area-inset-right)); padding: 3px; }
  .zoom button { width: 42px; height: 42px; }
  .actions { right: max(10px,env(safe-area-inset-right)); bottom: max(12px,env(safe-area-inset-bottom)); }
  .actions button { padding-inline: 8px; }
  .joystick { left: max(12px,env(safe-area-inset-left)); bottom: max(12px,env(safe-area-inset-bottom)); width: 85px; height: 85px; }
  .bottom { bottom: max(12px,env(safe-area-inset-bottom)); }
  .toast { bottom: calc(max(12px,env(safe-area-inset-bottom)) + 55px); }
}

#story::backdrop { background: #10182a68; }
@media (min-width: 850px) and (min-height: 560px) {
  #story {
    inset: auto auto max(100px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
    margin: 0;
    width: min(400px, 33vw);
  }
}
@media (max-width: 450px) and (orientation: portrait) {
  .bottom { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 53px); }
  .toast { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 95px); }
}

@media (max-width: 360px) {
  .place h1 { font-size: .83rem; }
  .language select { font-size: .71rem; }
}

.avatar-tools {
  display: flex;
  gap: 7px;
  bottom: max(26px, env(safe-area-inset-bottom));
  left: max(24px, env(safe-area-inset-left));
}
.avatar-tools button {
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  font-size: .72rem;
  font-weight: 820;
}
.avatar-tools button:hover, .avatar-tools button:active { background: #376751; }
#sprint[aria-pressed="true"] { background: #d8f3a9; color: #253d30; }
#emotes { width: min(320px, calc(100% - 26px)); }
.emote-choices { display: grid; gap: 7px; margin: 14px 0; }
.emote-choices button { text-align: left; background: #30594b; }
#wardrobe {
  width: min(840px, calc(100% - 30px));
  max-width: none;
  max-height: calc(100% - 26px);
  padding: 0;
  overflow: hidden;
}
#wardrobe[open] { display: flex; flex-direction: column; }
.wardrobe-heading, .wardrobe-footer { padding: 11px 16px; }
.wardrobe-heading { border-bottom: 1px solid var(--line); }
.wardrobe-heading h2 { margin: 2px 0; }
.wardrobe-body {
  display: grid;
  grid-template-columns: minmax(225px, .9fr) minmax(260px, 1.1fr);
  gap: 12px;
  padding: 12px 16px;
  overflow: auto;
  overscroll-behavior: contain;
  min-height: 0;
}
.wardrobe-preview {
  position: sticky;
  top: 0;
  height: clamp(225px, 49vh, 405px);
  overflow: hidden;
  align-self: start;
  border: 1px solid #a5cbb45e;
  border-radius: 13px;
  background: radial-gradient(ellipse at 50% 32%, #557e6a, #24473e 68%, #203930);
}
#look-preview {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#look-preview:active { cursor: grabbing; }
.preview-error { margin: 20px; }
.turn-look { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; }
.turn-look button { background: #183c33de; min-width: 40px; font-size: 1rem; }
.wardrobe-options { display: grid; gap: 7px; min-width: 0; }
.wardrobe-options fieldset {
  margin: 0;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 4px 6px 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.wardrobe-options legend { color: #f4da98; font-size: .69rem; font-weight: 750; padding: 0 4px; }
.look-choice {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  min-height: 34px;
  border-color: #cad7ad46;
  background: #2c4d40;
  font-size: .70rem;
}
.look-choice[aria-pressed="true"] { border-color: #e2edae; background: #506039; color: #fff4ce; }
.look-choice i { width: 11px; height: 11px; border: 1px solid #ffefdca8; border-radius: 50%; }
.wardrobe-footer { border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 6px; }
.wardrobe-footer div { display: flex; gap: 6px; }
@media (pointer: coarse) {
  .look-choice { min-height: 40px; }
  .avatar-tools {
    top: calc(max(22px,env(safe-area-inset-top)) + 163px);
    right: max(24px,env(safe-area-inset-right));
    left: auto;
    bottom: auto;
    display: grid;
  }
  .actions { display: grid; grid-template-columns: auto auto; }
  .actions #sprint { grid-row: 1; grid-column: 2; }
  .actions #interact { grid-row: 2; grid-column: 1; }
  .actions #jump { grid-row: 2; grid-column: 2; }
}
@media (max-width: 650px), (max-height: 470px) {
  .avatar-tools { bottom: 12px; left: 12px; gap: 4px; }
  .avatar-tools button { font-size: .65rem; padding-inline: 7px; min-height: 40px; }
}
@media (max-width: 650px) and (pointer: coarse), (max-height: 470px) and (pointer: coarse) {
  .avatar-tools { top: calc(max(9px, env(safe-area-inset-top)) + 155px); right: max(10px,env(safe-area-inset-right)); bottom: auto; left: auto; }
}
@media (max-width: 550px) {
  .wardrobe-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 8px; padding: 8px 10px; overflow: hidden; }
  .wardrobe-preview { position: relative; width: 100%; height: clamp(145px, 29vh, 245px); }
  .wardrobe-options { overflow-y: auto; overscroll-behavior: contain; padding-bottom: 2px; }

  .wardrobe-heading, .wardrobe-footer { padding: 8px 10px; }
  .wardrobe-footer button { padding-inline: 8px; }
}

body[data-touch="true"] .avatar-tools {
  top: calc(max(9px, env(safe-area-inset-top)) + 155px);
  right: max(10px,env(safe-area-inset-right));
  left: auto;
  bottom: auto;
  display: grid;
}
body[data-touch="true"] .actions { display: grid; grid-template-columns: auto auto; }
body[data-touch="true"] #sprint { grid-area: 1 / 2; }
body[data-touch="true"] #interact { grid-area: 2 / 1; }
body[data-touch="true"] #jump { grid-area: 2 / 2; }
@media (min-width: 651px) and (min-height: 471px) {
  body[data-touch="true"] .avatar-tools {
    top: calc(max(22px, env(safe-area-inset-top)) + 163px);
    right: max(24px, env(safe-area-inset-right));
  }
}

.direction { display: flex; gap: 6px; align-items: center; margin-top: 8px; font-size: .68rem; color: #ffe2ad; }
.direction i { display: inline-grid; place-items: center; width: 14px; height: 14px; color: #f4d288; font-size: .65rem; font-style: normal; }
#change-route {
  pointer-events: auto;
  border: 1px solid #c8d0df54;
  border-radius: 7px;
  padding: 5px 7px;
  min-height: 36px;
  margin-inline-start: auto;
  background: #344562;
  font-size: .66rem;
  font-weight: 750;
}
#change-route:hover { background: #435a80; }
.route-choices { display: grid; gap: 7px; margin: 10px 0; }
.route-choices button {
  text-align: left;
  background: #313f56;
  border-color: #c9b79e80;
  color: #ffebc2;
}
.route-choices button[aria-pressed="true"] { background: #4e4c53; border-color: #ffda93; }
.route-choices span { display: block; margin-top: 4px; font-size: .70rem; font-weight: 520; line-height: 1.4; color: #d9ddeb; }
.signal-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; max-width: 280px; }
#signal-target { margin-bottom: 8px; }
#signal-target span {
  display: grid;
  place-items: center;
  border: 1px solid #f8d48d65;
  border-radius: 9px;
  min-height: 44px;
  font-size: 1.5rem;
  background: #4a3c40;
  color: #ffe0a5;
}
#signal-input { margin-bottom: 14px; }
#signal-input button { min-height: 55px; background: #313f56; font-size: 1.5rem; }
.signal[data-match="true"] { border-color: #bbffc7; color: #bbffc7; }
#signal-confirm:disabled { opacity: .48; cursor: default; }
.audio-choice { display: flex; align-items: center; gap: 8px; margin: 7px 0 13px; font-size: .77rem; }
.audio-choice input { width: 18px; height: 18px; accent-color: #ebc781; }
.reveal {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  bottom: max(26px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #161d33e8;
  border: 1px solid #d8c09894;
  width: max-content;
  max-width: calc(100% - 26px);
  border-radius: 12px;
  padding: 7px 10px;
  color: #fff0ca;
}
.reveal p { margin: 0; font-size: .82rem; font-weight: 750; }
.reveal button { background: #394260; border: 1px solid #aeb5c56b; border-radius: 7px; min-height: 38px; padding: 5px 9px; }
body[data-reveal="true"] .hud, body[data-reveal="true"] .toast { visibility: hidden; }
@media (max-width: 650px), (max-height: 470px) {
  .direction { margin-top: 4px; font-size: .62rem; }
  #change-route { min-height: 34px; font-size: .60rem; padding: 3px 5px; }
  .quest-progress { align-items: center; }
  #story, #tuner { padding: 15px; }
  #story .route-choices { gap: 6px; }
}

#open-courtyard {
  pointer-events: auto;
  margin-top: 7px;
  background: #f0d196;
  color: #2a2940;
  min-height: 36px;
  border: 1px solid #ffe0a5;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: .75rem;
  font-weight: 790;
}
#open-courtyard:disabled { opacity: .58; }
