:root {
  --ink: #1f2a2e;
  --paper: #f6f2ea;
  --paper-2: #ece6da;
  --line: #d6cdbd;
  --muted: #6c6a63;
  --accent: #c8643b;
  --accent-ink: #fff;
  --sky: #c9d6d8;
  --shadow: 0 6px 24px rgba(20, 28, 30, .18);
  --r: 10px;
  font-family: "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } /* holds are long-press info, not a callout */
button { font: inherit; color: inherit; cursor: pointer; }

.bar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); pointer-events: none; }
.bar > * { pointer-events: auto; }
.brand { margin-right: auto; display: flex; align-items: center; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 12px; box-shadow: var(--shadow); }
.brand b { font-size: 18px; letter-spacing: .02em; }
.tag { color: var(--muted); font-size: 13px; }
.logo { width: 18px; height: 18px; border-radius: 3px; background:
  linear-gradient(90deg, transparent 32%, rgba(0,0,0,.25) 33% 34%, transparent 35% 65%, rgba(0,0,0,.25) 66% 67%, transparent 68%),
  linear-gradient(0deg, transparent 32%, rgba(0,0,0,.25) 33% 34%, transparent 35% 65%, rgba(0,0,0,.25) 66% 67%, transparent 68%),
  linear-gradient(135deg, #e0c78a 0 45%, #b89c78 45% 70%, #3d7fd6 70%); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 14px; box-shadow: var(--shadow); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.primary { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
.ghost { background: transparent; border: 1px solid var(--line); }

.agents { position: fixed; left: 16px; top: 70px; width: 200px; max-height: 40vh; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.agents-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.agents-head b { color: var(--ink); }
.agents ul { list-style: none; margin: 0; padding: 4px; overflow: auto; }
.agents li button { width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 6px; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.agents li button:hover { background: var(--paper-2); }
.agents .kind { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.agents[data-collapsed="true"] ul { display: none; }

.info { position: fixed; right: 16px; top: 70px; width: 340px; max-height: calc(100vh - 90px); overflow: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
.info .close { position: absolute; right: 8px; top: 6px; background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); }
.info h3 { margin: 0 0 2px; font-size: 20px; }
.info .coord { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.grid10 { display: grid; grid-template-columns: repeat(10, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); aspect-ratio: 1; width: 100%; }
.grid10 i { display: block; }
.legend { list-style: none; padding: 0; margin: 10px 0; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.legend .dot { width: 12px; height: 12px; border-radius: 2px; border: 1px solid rgba(0,0,0,.15); flex: none; }
.legend .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; margin: 8px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.info details { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; font-size: 13px; }
.info details p { margin: 4px 0; }
.info summary { cursor: pointer; font-weight: 600; }
.src { color: var(--muted); font-size: 12px; }

.play { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: min(560px, calc(100% - 32px)); background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 10px 12px; }
.play-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.play .me { font-weight: 700; font-size: 14px; margin-right: auto; }
.slots { display: flex; gap: 6px; }
.slot { width: 44px; height: 44px; padding: 0; border: 2px solid var(--line); border-radius: 6px; background: var(--paper-2); overflow: hidden; }
.slot[aria-pressed="true"] { border-color: var(--accent); }
.slot canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.tools { margin-top: 8px; }
.tools button { flex: 1 1 auto; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 14px; }
.tools button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); top: 70px; background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--paper); color: var(--ink); padding: 18px; width: min(520px, calc(100% - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20, 28, 30, .35); }
dialog h2 { margin: 0 0 4px; font-size: 20px; }
dialog .sub { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
dialog label { display: block; margin: 8px 0; font-size: 14px; }
dialog input[type="text"], dialog input:not([type]) { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; }
dialog fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; padding: 6px 10px 10px; }
dialog legend { font-size: 13px; color: var(--muted); }
dialog .opt { display: inline-flex; gap: 6px; margin-right: 14px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
dialog .row button { padding: 8px 16px; border-radius: 8px; }
dialog pre { background: var(--ink); color: #e9e4d8; padding: 10px; border-radius: 8px; overflow: auto; font-size: 12px; max-height: 40vh; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.swatches button[aria-pressed="true"] { border-color: var(--ink); }
.err { color: #a3361a; font-size: 13px; }

#alal-topbar-extra { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#alal-topbar-extra:empty { display: none; }
.agents li button.asleep { color: var(--muted); }
.agents .zzz { margin-left: auto; font-size: 11px; color: var(--muted); }

/* First-person view */
.crosshair { position: fixed; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; pointer-events: none; display: none;
  background: linear-gradient(var(--paper), var(--paper)) center / 2px 100% no-repeat, linear-gradient(var(--paper), var(--paper)) center / 100% 2px no-repeat;
  filter: drop-shadow(0 0 1px rgba(0,0,0,.8)); }
body.fp:not(.fp-touch) .crosshair { display: block; }
.joy { position: fixed; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); width: 120px; height: 120px; border-radius: 50%; display: none;
  background: rgba(246, 242, 234, .28); border: 2px solid rgba(246, 242, 234, .75); box-shadow: var(--shadow); touch-action: none; place-items: center; }
.joy-knob { width: 52px; height: 52px; border-radius: 50%; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); pointer-events: none; }
body.fp-touch .joy { display: grid; }
body.fp-touch .agents { display: none; }
body.fp-touch.playing .joy { bottom: 200px; }

.loading { position: fixed; inset: 0; display: grid; place-items: center; font-size: 15px; color: var(--muted); pointer-events: none; }
.og-title { position: fixed; left: 56px; bottom: 56px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 18px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.og-title b { font-size: 72px; line-height: 1; }
.og-title span { font-size: 30px; color: var(--muted); margin-top: 8px; }
body.og .bar, body.og .agents, body.og .info, body.og .play, body.og .joy, body.og .crosshair, body.og .toast { display: none !important; }

@media (max-width: 720px) {
  .tag { display: none; }
  .bar { padding: 8px 16px; flex-wrap: wrap; }
  .chip { padding: 6px 10px; font-size: 13px; }
  .agents { top: auto; bottom: 16px; width: 150px; max-height: 30vh; }
  .toast { top: 108px; }
  body.playing .agents { display: none; }
  .info { left: 16px; right: 16px; width: auto; top: auto; bottom: 16px; max-height: 55vh; }
  body.playing .info { bottom: 170px; max-height: 40vh; }
  .grid10 { width: 60%; margin: 0 auto; }
  /* First person on a phone: the left-bottom belongs to the joystick, so the info sheet moves up. */
  /* Content height, scrolling inside past the room between the measured top bar and the joystick (120px + 16px + gap). */
  body.fp-touch .info { top: var(--alal-top, 112px); bottom: auto; max-height: calc(var(--alal-vh, 100dvh) - var(--alal-top, 112px) - 152px); }
  body.fp-touch .info .grid10 { width: 40%; }
}

/* Phones: keep the name, 설치, clock and 도감 on the first row (two rows in all) at 360-390 px wide.
   Buttons keep their 30 px height; only side padding and gaps shrink. */
@media (max-width: 480px) {
  .bar { padding-left: 8px; padding-right: 8px; gap: 6px; }
  .brand { gap: 6px; padding: 6px 8px; }
  .brand b { font-size: 15px; letter-spacing: 0; }
  .logo { width: 15px; height: 15px; }
  #btn-install, .alal-pn-dexbtn { padding-left: 8px; padding-right: 8px; }
}
