/* Space page. Ink background, warm paper text, one amber accent for actions.
   System fonts on purpose: the model is the page's download budget, not a web font. */
:root {
  --ink: #101218;
  --ink-2: #181b23;
  --ink-3: #232733;
  --line: rgba(243, 237, 226, 0.14);
  --paper: #f3ede2;
  --paper-dim: #b9b2a6;
  --amber: #e4a853;
  --amber-ink: #241a08;
  --danger: #e07a6b;
  --r-s: 6px;
  --r-m: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: var(--ink); color: var(--paper); font: 15px/1.45 var(--font); }
/* The space page never scrolls (owner 11/06 「스크롤이 생긴다」): iOS Safari still scrolls / rubber-bands the
   document when only body is overflow:hidden, so html is locked too and body is pinned to the viewport. */
html { overflow: hidden; overscroll-behavior: none; }
body { overflow: hidden; overscroll-behavior: none; }
body:not(.message) { position: fixed; inset: 0; height: 100%; height: 100dvh; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

#space { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#view:active { cursor: grabbing; }

/* top-left: space name and how many are here */
.top {
  position: absolute; top: calc(12px + var(--safe-t)); left: calc(12px + var(--safe-l));
  display: flex; align-items: baseline; gap: 10px; pointer-events: none; max-width: calc(100% - 24px);
}
.space-name {
  margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
  padding: 6px 12px; background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r-m);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.here { margin: 0; font-size: 13px; color: var(--amber); font-variant-numeric: tabular-nums; }
.offline .here { color: var(--paper-dim); }

/* loading */
.loading {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 14px; justify-items: center;
  background: var(--ink); transition: opacity 0.35s ease;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading-bar { width: min(240px, 60vw); height: 3px; background: var(--ink-3); border-radius: 2px; overflow: hidden; }
.loading-bar span { display: block; height: 100%; background: var(--amber); transform-origin: left; transform: scaleX(0.02); transition: transform 0.2s linear; }
.loading p { margin: 0; color: var(--paper-dim); font-size: 14px; }
.loading.failed .loading-bar span { background: var(--danger); }
.noscript { position: absolute; inset: 0; display: grid; place-content: center; margin: 0; }

/* name tags (placed by the viewer with transform) */
.tags { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.tag {
  position: absolute; left: 0; top: 0; padding: 2px 8px; font-size: 13px; font-weight: 600;
  background: rgba(16, 18, 24, 0.78); border-radius: var(--r-s); white-space: nowrap; will-change: transform;
}

/* touch stick */
.stick {
  position: absolute; left: calc(24px + var(--safe-l)); bottom: calc(28px + var(--safe-b));
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(24, 27, 35, 0.55); border: 1px solid var(--line); touch-action: none;
  display: grid; place-items: center;
}
#space:has(.chat.open) .stick { display: none; }
.stick-knob { width: 48px; height: 48px; border-radius: 50%; background: var(--paper); opacity: 0.9; transition: transform 0.06s linear; }

/* chat */
.chat {
  position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(12px + var(--safe-b));
  width: min(340px, calc(100% - 24px)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.chat-toggle {
  border: 1px solid var(--line); background: var(--ink-2); padding: 8px 14px; border-radius: var(--r-m); font-weight: 600;
  position: relative;
}
.chat-toggle.unread::after {
  content: ""; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--amber);
}
.chat-lines, .chat-form { display: none; }
.chat.open .chat-lines {
  display: block; list-style: none; margin: 0; padding: 8px 10px; width: 100%; max-height: min(38vh, 300px); overflow-y: auto;
  background: rgba(16, 18, 24, 0.86); border: 1px solid var(--line); border-radius: var(--r-m);
}
.chat.open .chat-form { display: flex; gap: 6px; width: 100%; }
.chat-lines li { padding: 3px 0; font-size: 14px; overflow-wrap: anywhere; position: relative; }
.chat-lines li b { margin-right: 6px; color: var(--paper-dim); font-weight: 600; }
.chat-lines li.mine b { color: var(--amber); }
.chat-lines li.notice { color: var(--paper-dim); font-size: 13px; }
.line-more { border: 0; background: none; padding: 0 4px; margin-left: 4px; color: var(--paper-dim); }
.line-menu { display: inline-flex; gap: 4px; margin-left: 6px; font-size: 13px; color: var(--paper-dim); }
.line-menu button { border: 1px solid var(--line); background: var(--ink-3); border-radius: var(--r-s); padding: 1px 8px; }
.chat-form input {
  flex: 1; min-width: 0; padding: 9px 12px; background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--r-m);
}
.chat-form button, .name-actions button[type="submit"] {
  border: 0; background: var(--amber); color: var(--amber-ink); padding: 9px 16px; border-radius: var(--r-m); font-weight: 700;
}
.chat-form button:active, .name-actions button:active { transform: translateY(1px); }

/* name */
.name-box {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(340px, calc(100% - 32px));
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: grid; gap: 16px;
}
.name-box label { display: grid; gap: 8px; font-weight: 700; font-size: 16px; }
.name-box input {
  padding: 11px 12px; background: var(--ink); border: 1px solid var(--line); border-radius: var(--r-m); font-weight: 400;
}
.name-actions { display: flex; justify-content: flex-end; gap: 8px; }
.name-actions .quiet { border: 1px solid var(--line); background: none; padding: 9px 14px; border-radius: var(--r-m); }

/* made with */
.made {
  position: fixed; left: calc(12px + var(--safe-l)); bottom: calc(8px + var(--safe-b)); font-size: 12px;
  color: var(--paper-dim); text-decoration: none; padding: 2px 8px; border-radius: var(--r-s); background: rgba(16, 18, 24, 0.72);
}
@media (pointer: coarse) { .made { left: auto; right: calc(12px + var(--safe-r)); bottom: auto; top: calc(14px + var(--safe-t)); } }

/* pay button (plan D): top right; on touch below the 「흐름으로 만듦」 tag that sits there */
.pay {
  position: absolute; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r));
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: min(260px, calc(100% - 24px));
}
.pay-btn {
  display: inline-block; padding: 9px 16px; border-radius: var(--r-m); background: var(--amber); color: var(--amber-ink);
  font-weight: 700; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}
.pay-btn:hover { filter: brightness(1.06); }
.pay-btn:active { transform: translateY(1px); }
.pay-note {
  margin: 0; padding: 4px 10px; font-size: 13px; border-radius: var(--r-s); background: var(--ink-2);
  border: 1px solid var(--line); color: var(--paper-dim); overflow-wrap: anywhere;
}
.pay-note.bought { color: var(--amber); }
@media (pointer: coarse) { .pay { top: calc(46px + var(--safe-t)); } }

/* message pages (404 / 503) */
body.message { overflow: auto; display: grid; place-content: center; min-height: 100%; padding: 24px; }
body.message main { max-width: 420px; }
body.message h1 { font-size: 22px; margin: 0 0 8px; }
body.message p { margin: 0; color: var(--paper-dim); }

@media (prefers-reduced-motion: reduce) {
  .loading, .loading-bar span, .stick-knob { transition: none; }
}
