:root { --bg: #0d1117; --panel: rgba(16, 22, 32, .82); --line: rgba(255, 255, 255, .12); --text: #e6edf3; --dim: #9aa7b4; --accent: #4cc2ff; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; overflow: hidden; }
#app { position: fixed; inset: 0; }
#gl { width: 100%; height: 100%; display: block; outline: none; touch-action: none; }

.tag { position: absolute; top: 10px; padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-weight: 600; letter-spacing: .02em; pointer-events: none; white-space: nowrap; }
#tag-world { left: 10px; }
#tag-map { left: calc(50% + 10px); }

#hud { position: absolute; top: 44px; left: calc(50% + 10px); min-width: 190px; padding: 8px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); pointer-events: none; }
#hud .row { display: flex; justify-content: space-between; gap: 14px; color: var(--dim); }
#hud .row b { color: var(--text); font-variant-numeric: tabular-nums; }
#hud .state { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); color: var(--accent); }

#insets { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 8px; align-items: flex-end; pointer-events: none; }
#insets figure { margin: 0; padding: 4px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); }
#insets canvas { display: block; width: 176px; height: auto; image-rendering: pixelated; border-radius: 4px; background: #000; }
#insets #c-map { width: 230px; }
#insets figcaption { margin-top: 3px; color: var(--dim); font-size: 11px; text-align: center; }

#panel { position: absolute; right: 10px; bottom: 10px; width: 250px; padding: 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
#panel .group { margin-bottom: 8px; }
#panel label { display: block; margin-bottom: 3px; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { flex: 1; }
button { appearance: none; border: 0; padding: 6px 4px; background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
button:hover { background: rgba(255, 255, 255, .07); }
button.on { background: var(--accent); color: #04121c; font-weight: 600; }
.buttons { display: flex; gap: 6px; }
.buttons button { flex: 1; border: 1px solid var(--line); border-radius: 7px; }
.hint { margin: 0; color: var(--dim); font-size: 11px; }

#pad { position: absolute; right: 270px; bottom: 14px; display: none; flex-direction: column; align-items: center; gap: 4px; }
#pad div { display: flex; gap: 4px; }
#pad button { width: 44px; height: 44px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 16px; }
@media (pointer: coarse) { #pad { display: flex; } }

/* keyboard legend: sits between the insets and the panel, lights up with the keys */
#keys { position: absolute; left: 652px; bottom: 10px; padding: 8px 14px 9px; border-radius: 10px; background: var(--panel); border: 1px solid var(--accent); text-align: center; }
.keys-title { margin-bottom: 7px; color: var(--accent); font-weight: 700; white-space: nowrap; }
.keys-grid { display: grid; grid-template-columns: repeat(3, 36px); grid-template-rows: repeat(2, 32px); gap: 4px; justify-content: center; }
.keys-grid button { padding: 0; border: 1px solid rgba(255, 255, 255, .28); border-bottom-width: 3px; border-radius: 6px; background: rgba(255, 255, 255, .07); font-weight: 700; }
.keys-grid button:nth-child(1) { grid-area: 1 / 2; }
.keys-grid button:nth-child(2) { grid-area: 2 / 1; }
.keys-grid button:nth-child(3) { grid-area: 2 / 2; }
.keys-grid button:nth-child(4) { grid-area: 2 / 3; }
.keys-grid button.down { background: var(--accent); border-color: var(--accent); color: #04121c; transform: translateY(2px); border-bottom-width: 1px; }
.keys-sub { margin-top: 7px; color: var(--dim); font-size: 11px; white-space: nowrap; }
#keys.nudge .keys-grid button { animation: nudge 1.8s ease-in-out infinite; }
#keys.nudge .keys-grid button:nth-child(2) { animation-delay: .15s; }
#keys.nudge .keys-grid button:nth-child(3) { animation-delay: .3s; }
#keys.nudge .keys-grid button:nth-child(4) { animation-delay: .45s; }
@keyframes nudge { 0%, 60%, 100% { border-color: rgba(255, 255, 255, .28); box-shadow: none; } 30% { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76, 194, 255, .28); } }
@media (max-width: 1089px) { #keys { left: 10px; bottom: 186px; } }
@media (pointer: coarse) { #keys { display: none; } }

#loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); text-align: center; color: var(--dim); }
.spinner { width: 28px; height: 28px; margin: 0 auto 10px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* stacked layout: world on top, map below */
@media (max-aspect-ratio: 1/1), (max-width: 760px) {
  #tag-map { left: 10px; top: calc(50% + 10px); }
  #hud { left: 10px; top: calc(50% + 44px); }
  #insets #c-map, #insets figure:first-child { display: none; }
  #insets canvas { width: 120px; }
  #panel { width: 210px; padding: 8px; }
  #pad { right: 10px; bottom: 300px; }
  #keys { left: 10px; bottom: 150px; }
}
