* { box-sizing: border-box; }
:root {
  font-family: system-ui, sans-serif;
  color: #183a36;
  background: #d7e9e2;
  --panel: #f8f5eb;
  --line: #bacbc1;
  --accent: #1e5147;
}
body { margin: 0; }
[hidden] { display: none !important; }
#stage { width: 100%; height: 100dvh; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#hud, #controls, #lookup {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 24px #133b3320;
}
#hud { position: fixed; top: 24px; left: 24px; padding: 18px 22px; pointer-events: none; }
.brand { display: flex; align-items: center; gap: 8px; font: 750 13px ui-monospace, monospace; letter-spacing: .1em; }
.brand > span:first-child { width: 10px; height: 10px; background: #bf714a; transform: rotate(45deg); margin-right: 3px; }
.brand-sub { color: #4c6b61; font-size: 10px; }
h1 { margin: 10px 0 5px; font-size: 28px; line-height: 1.15; }
#status { margin: 0; color: #47685f; font-size: 13px; }
#world-controls {
  position: fixed;
  bottom: 24px;
  left: 24px;
  display: grid;
  justify-items: start;
  gap: 6px;
}
#controls { padding: 6px; display: flex; align-items: center; gap: 5px; }
button, select {
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
}
button, select { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
button:hover:not(:disabled), select:hover { background: #dce9df; }
button:focus-visible, select:focus-visible, a:focus-visible, canvas:focus-visible { outline: 2px solid #bf714a; outline-offset: 2px; }

#work { margin: 6px 0 0; color: #47685f; font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#lookup { width: 315px; max-width: 100%; padding: 9px 10px 10px; }
#search-label { display: block; margin: 0 0 5px 2px; color: var(--accent); font-size: 13px; font-weight: 700; }
.lookup-row { display: flex; gap: 5px; }
#lookup input {
  width: 100%;
  min-width: 0;
  padding: 0 9px;
  background: #fffdf6;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: inherit;
  font: inherit;
  font-size: 16px;
}
#lookup input::placeholder { font-size: 13px; }
#lookup input:focus-visible { outline: 2px solid #bf714a; outline-offset: 2px; }
#lookup button {
  flex: 0 0 auto;
  min-height: 44px;
  border-color: var(--line);
  background: #eaf0e3;
  color: var(--accent);
  font-weight: 650;
  white-space: nowrap;
}
#selection { margin: 6px 2px 0; color: #47685f; font-size: 12px; overflow-wrap: anywhere; }
#selection:empty { display: none; }

body.portrait { display: grid; place-items: center; min-height: 100dvh; background: #172d2a; }
body.portrait #stage { width: min(100vw, 56.25dvh); height: auto; aspect-ratio: 9 / 16; margin: auto; }
#studio {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(360px, calc(100vw - 48px));
  max-height: calc(100dvh - 48px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 8px 24px #133b3320;
}
#shot-settings { margin-top: 10px; border-block: 1px solid var(--line); padding-block: 4px; }
#shot-settings summary { min-height: 36px; padding: 8px 3px; cursor: pointer; font-size: 14px; font-weight: 650; }
#shot-script {
  display: block;
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffdf6;
  padding: 8px;
  color: inherit;
  font: inherit;
}
#shot-hint { color: #47685f; }
#shot-status:empty { display: none; }
#studio h2 { margin: 0 0 8px; font-size: 18px; }
#studio p { margin: 6px 0; font-size: 12px; }
.studio-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.studio-row > * { font-size: 13px; }
.studio-row label { padding: 6px; }
.studio-row a { padding: 7px; color: var(--accent); }
#studio button, #studio select, .file-button { border: 1px solid var(--line); min-height: 35px; }
.file-button { position: relative; display: inline-flex; align-items: center; border-radius: 8px; }
.file-button input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.file-button:focus-within { outline: 2px solid #bf714a; outline-offset: 2px; }
body.clean :is(#hud, #world-controls, #studio) { display: none !important; }
#restore-ui { position: fixed; top: 12px; right: 12px; background: var(--panel); border-color: var(--line); }

#controls [aria-expanded="true"] { background: #dae8df; }
#studio { overscroll-behavior: contain; }

@media (max-width: 720px), (max-width: 940px) and (max-height: 480px) {
  #hud {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    padding: 11px 13px;
  }
  .brand { font-size: 11px; }
  .brand-sub { font-size: 9px; }
  h1 { font-size: 22px; margin-top: 7px; }
  #status, #work { font-size: 11px; }
  #world-controls {
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    justify-items: stretch;
  }
  #lookup { width: auto; }
  #controls {
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
  }
  #controls > *, #studio button, #studio select, #studio label, #shot-settings summary {
    min-height: 44px;
  }
  #controls > * { flex: 0 1 auto; padding-inline: 7px; }
  #studio {
    top: auto;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    width: auto;
    bottom: calc(8px + max(12px, env(safe-area-inset-bottom)) + var(--controls-height, 54px));
    max-height: min(50dvh, 380px);
    overflow: auto;
  }
  #restore-ui { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }
}

@media (max-height: 480px) and (max-width: 940px) {
  #hud { padding-block: 8px; }
  #studio { max-height: 45dvh; }
}
