:root {
  --ink: #f6efe4;
  --muted: rgba(246, 239, 228, 0.62);
  --glass: rgba(18, 26, 42, 0.55);
  --line: rgba(255, 255, 255, 0.14);
  --warm: #ffb45e;
  --red: #e2564d;
  --bg: #0b1424;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 80%, rgba(255, 170, 90, 0.10), transparent 60%),
    linear-gradient(to bottom, rgba(8, 14, 26, 0.35), rgba(8, 14, 26, 0.7));
  transition: opacity 0.8s ease;
}
.overlay.leaving { opacity: 0; pointer-events: none; }

.card {
  width: min(420px, 100%);
  padding: 32px 28px 28px;
  border-radius: 24px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.badge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--warm);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 180, 94, 0.35);
  background: rgba(255, 180, 94, 0.08);
}

h1 {
  font-family: Fraunces, Georgia, serif;
  font-weight: 600;
  font-size: clamp(28px, 7vw, 38px);
  line-height: 1.1;
  margin: 18px 0 10px;
}

.sub { color: var(--muted); line-height: 1.55; margin: 0 0 24px; font-size: 15px; }

#entry-form { display: flex; gap: 10px; }
#entry-form.stack { flex-direction: column; }

input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  user-select: text;
}
input:focus { border-color: rgba(255, 180, 94, 0.6); }
input::placeholder { color: rgba(246, 239, 228, 0.4); }

button {
  font: inherit;
  font-weight: 600;
  padding: 13px 18px;
  border: 0;
  border-radius: 14px;
  color: #2a1606;
  background: linear-gradient(180deg, #ffc985, var(--warm));
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(255, 160, 70, 0.35);
}
button:active { transform: translateY(1px); }

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
.chip, .hint {
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 13px;
}
.chip { font-weight: 600; white-space: nowrap; }
.hint { color: var(--muted); transition: opacity 1s ease; }

#joystick {
  position: fixed;
  left: 24px;
  bottom: 28px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
#stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}

@media (max-width: 600px) {
  .hint { display: none; }
}

/* ── week 2: notes ── */
h2 { font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: 22px; margin: 0; }

.overlay.dim { background: rgba(8, 14, 26, 0.55); z-index: 5; }
#note-form h2 { margin-bottom: 16px; }

textarea {
  width: 100%;
  font: inherit;
  line-height: 1.5;
  color: var(--ink);
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  resize: none;
  user-select: text;
}
textarea:focus { border-color: rgba(255, 180, 94, 0.6); }
textarea::placeholder { color: rgba(246, 239, 228, 0.4); }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.count { color: var(--muted); font-size: 13px; }
.error { color: #ff9d94; font-size: 13px; margin: 0; min-height: 1em; }
#entry-error { margin-top: 12px; }

button:disabled { opacity: 0.55; cursor: default; }
button.ghost, button.glass {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  box-shadow: none;
  font-weight: 500;
}
button.glass { background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
button.small { padding: 5px 10px; font-size: 12px; border-radius: 9px; margin-left: auto; }

#hud .chip.link { pointer-events: auto; cursor: pointer; color: var(--ink); box-shadow: none; font: inherit; font-size: 13px; font-weight: 600; }

.bottom {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  pointer-events: none;
}
.bottom > * { pointer-events: auto; }

#toast {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid rgba(255, 180, 94, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 14px;
  z-index: 6;
}

.card.tall { display: flex; flex-direction: column; max-height: min(620px, 86vh); width: min(460px, 100%); }
#notes-list { margin-top: 16px; overflow-y: auto; display: grid; gap: 10px; touch-action: pan-y; }
.note { padding: 13px 15px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); }
.note header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.note header span { color: var(--muted); font-size: 12px; }
.note p { margin: 0; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.empty { color: var(--muted); margin: 8px 0; }

@media (max-width: 600px) {
  #joystick { bottom: 96px; }
}

/* ── letters & paper designs ── */
.picker { margin-bottom: 12px; }
.swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--paper-accent);
  box-shadow: none;
}
.swatch[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 3px; }

#note-form textarea {
  background: var(--paper);
  color: var(--paper-ink);
  border: 1px solid var(--paper-accent);
  border-top-width: 6px;
}
#note-form textarea::placeholder { color: var(--paper-ink); opacity: 0.45; }

.paper {
  padding: 18px 18px 14px;
  border-radius: 14px;
  background: var(--paper);
  color: var(--paper-ink);
  border-top: 6px solid var(--paper-accent);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.paper p { margin: 0 0 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.paper footer { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
.paper footer span { opacity: 0.6; font-size: 12px; }
.paper button.small {
  color: var(--paper-ink);
  background: transparent;
  border: 1px solid var(--paper-accent);
  box-shadow: none;
  font-weight: 500;
}

.letter-wrap { width: min(420px, 100%); }
.letter-wrap .paper { padding: 28px 26px 20px; font-size: 17px; transform: rotate(-1deg); }
.letter-wrap .paper p { min-height: 90px; }

/* ── owner sign-in ── */
.fine { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 0; }
#owner-form h2 { margin-bottom: 8px; }
#owner-form .sub { margin-bottom: 16px; }
#owner-form input { width: 100%; }
#owner-form .error { margin-top: 10px; }
#hud .row { gap: 8px; }

/* ── realtime: chat ── */
#chat-form {
  position: fixed;
  right: 16px;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(280px, calc(100vw - 32px));
  z-index: 2;
}
#chat-input {
  width: 100%;
  padding: 11px 16px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 14px;
}
#people { font-weight: 500; color: var(--muted); }

@media (max-width: 700px) {
  #hud { top: 12px; left: 12px; right: 12px; gap: 6px; flex-wrap: wrap; }
  #hud .row { gap: 6px; }
  #hud .chip { padding: 7px 11px; font-size: 12px; }
  #street-label { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; }
  #toast { top: 60px; font-size: 13px; }
  #chat-form { left: 16px; right: 16px; width: auto; }
  .bottom { bottom: calc(max(24px, env(safe-area-inset-bottom)) + 56px); }
  #joystick { bottom: 160px; }
}

/* ── going in and out of the home ── */
#fade {
  position: fixed;
  inset: 0;
  background: #0d0a12;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease;
  z-index: 4;
}
#fade.on { opacity: 1; }

/* ── settings, decorating, music ── */
#settings-form h2 { margin-bottom: 18px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; font-size: 14px; color: var(--muted); }
select {
  font: inherit;
  color: var(--ink);
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
}
select option { color: #1b2030; }
.check { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; font-size: 13.5px; line-height: 1.5; color: var(--muted); cursor: pointer; }
.check strong { color: var(--ink); font-weight: 600; }
.check input { flex: none; width: 18px; height: 18px; margin-top: 2px; padding: 0; accent-color: var(--warm); }
.check input:disabled + span { opacity: 0.6; }

#decor-panel .sub { margin: 10px 0 16px; }
#decor-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile { display: grid; gap: 4px; justify-items: center; padding: 12px 4px; font-size: 12px; white-space: normal; }
.tile-icon { font-size: 26px; line-height: 1; }
@media (max-width: 420px) { #decor-grid { grid-template-columns: repeat(3, 1fr); } }

#hud .chip.link.on { border-color: rgba(255, 180, 94, 0.6); color: var(--warm); }
.sealed-note { font-style: italic; opacity: 0.75; }

/* ── polish: paper patterns, coat picker ── */
.paper, #note-form textarea { background-image: var(--paper-pattern, none); }
.swatch { background-image: var(--paper-pattern, none); }
#coat-row { margin: 14px 0 0; }
.swatch.coat { width: 26px; height: 26px; background-image: none; }

/* ── chat log ── */
#chat-log {
  position: fixed;
  right: 16px;
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 52px);
  width: min(280px, calc(100vw - 32px));
  max-height: 168px;
  overflow-y: auto;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(18, 26, 42, 0.42);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
  line-height: 1.45;
  touch-action: pan-y;
  user-select: text;
  z-index: 2;
}
#chat-log p { margin: 0 0 4px; overflow-wrap: anywhere; }
#chat-log p:last-child { margin-bottom: 0; }
#chat-log strong { color: var(--warm); font-weight: 600; }
#lang-btn { margin-left: auto; }

@media (max-width: 700px) {
  /* on phones the bottom belongs to the joystick and buttons: the log sits under the top bar */
  #chat-log { left: 12px; right: 12px; width: auto; top: 96px; bottom: auto; max-height: 78px; font-size: 12.5px; }
  #toast { top: 182px; }
}

/* ── Korean: a font that has the glyphs, and never break a word in the middle ── */
:lang(ko) body { word-break: keep-all; }
:lang(ko) h1, :lang(ko) h2 {
  font-family: Inter, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}
:lang(ko) h1 { font-size: clamp(26px, 6.4vw, 34px); line-height: 1.22; }

/* ── drawing board ── */
#draw-toggle { margin: 10px 0 0; }
#board { margin-top: 10px; }
.board-canvas, .letter-drawing {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 12px;
}
.board-canvas {
  background-color: var(--paper);
  background-image: var(--paper-pattern, none);
  border: 1px solid var(--paper-accent);
  touch-action: none; /* drawing, not scrolling */
  cursor: crosshair;
}
.letter-drawing { margin-bottom: 12px; }
.board-tools { display: grid; gap: 8px; margin-top: 10px; }
.board-inks, .board-pens { flex-wrap: wrap; gap: 6px; }
.ink, .pen {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: none;
  flex: none;
}
.pen { display: grid; place-items: center; background: rgba(255, 255, 255, 0.08); }
.pen span { display: block; border-radius: 50%; background: var(--ink); }
.ink[aria-pressed="true"], .pen[aria-pressed="true"] { outline: 2px solid var(--warm); outline-offset: 2px; }
.board-pens .small { margin-left: 0; }
.board-pens .small:first-of-type { margin-left: auto; }
#note-modal .card { max-height: 94vh; overflow-y: auto; }

/* ── rearranging decorations ── */
#decor-edit button { padding: 11px 14px; font-size: 14px; }
#decor-edit .chip { align-self: center; }
/* on wide screens the chat box owns the bottom-right corner: keep the bar to its left */
@media (min-width: 701px) { #decor-edit { right: 312px; justify-content: flex-start; } }

/* ── account section in settings ── */
details.account { margin: 0 0 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); font-size: 13.5px; }
details.account summary { cursor: pointer; color: var(--ink); font-weight: 600; }
details.account[open] summary { margin-bottom: 10px; }
details.account input { width: 100%; margin-bottom: 8px; }
details.account .fine { margin-bottom: 10px; }
details.danger { border-color: rgba(255, 120, 110, 0.35); }
details.danger summary, details.danger button { color: #ff9d94; }
#settings-form { max-height: 92vh; overflow-y: auto; }

/* ── badges ── */
.caution { color: #ffd9a0; }
#badges-modal .sub { margin: 10px 0 16px; }
#badges-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.badge { display: grid; gap: 3px; padding: 12px; border-radius: 14px; border: 1px solid var(--line); font-size: 13.5px; opacity: 0.5; }
.badge.got { opacity: 1; border-color: rgba(255, 180, 94, 0.55); background: rgba(255, 180, 94, 0.08); }
.badge-icon { font-size: 26px; line-height: 1.1; filter: grayscale(1); }
.badge.got .badge-icon { filter: none; }
.badge-how { color: var(--muted); font-size: 12px; line-height: 1.4; text-transform: none; letter-spacing: 0; font-weight: 400; }

/* ── postcard: the link-preview picture (?postcard) ── */
.postcard #entry, .postcard #hud, .postcard .bottom, .postcard #chat-form, .postcard #chat-log { display: none !important; }
#postcard {
  position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 14px;
  padding: 0 64px 56px; pointer-events: none;
  background: linear-gradient(180deg, rgba(10, 12, 30, 0) 45%, rgba(10, 12, 30, 0.78) 100%);
}
#postcard strong { font-family: 'Fraunces', serif; font-weight: 600; font-size: 68px; line-height: 1.12; color: var(--ink); text-shadow: 0 2px 24px rgba(0, 0, 0, 0.5); }
:lang(ko) #postcard strong { font-family: inherit; font-weight: 700; font-size: 62px; letter-spacing: -0.02em; }
.postcard-brand { color: var(--warm); font-size: 22px; font-weight: 600; letter-spacing: 0.22em; }

[hidden] { display: none !important; }
