:root {
  --paper: #fbf7ef;
  --paper-2: #f1e9da;
  --ink: #43392f;
  --ink-soft: #7c6f61;
  --line: #e1d6c2;
  --accent: #6f8f6c;
  --accent-ink: #ffffff;
  --shadow: 0 10px 30px rgba(74, 56, 34, 0.16);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e7dfd0;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

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

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* 입장 화면 */
.entry {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(231, 223, 208, 0.72);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.entry-card {
  width: min(360px, 100%);
  padding: 28px 24px 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}
.entry-card h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: 0; }
.lead { margin: -8px 0 4px; color: var(--ink-soft); font-size: 15px; }
.field { display: grid; gap: 8px; }
.label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
input, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 16px;
}
textarea { resize: none; line-height: 1.5; }
input:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.char {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 10px 4px 8px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-size: 13px;
}
.char[aria-checked="true"] { border-color: var(--accent); background: #f2f6ee; font-weight: 600; }
.figure { position: relative; width: 34px; height: 46px; }
.figure::before {
  content: "";
  position: absolute;
  left: 7px; top: 0;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #f3cfae;
  box-shadow: inset 0 7px 0 var(--hair);
}
.figure::after {
  content: "";
  position: absolute;
  left: 3px; top: 19px;
  width: 28px; height: 27px;
  border-radius: 12px 12px 9px 9px;
  background: var(--body);
}

.primary {
  padding: 13px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.05); }
.ghost {
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
}
.ghost:hover { background: var(--paper-2); }
.text-btn { padding: 6px 2px; border: 0; background: none; color: var(--ink-soft); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.fine { margin: 0; font-size: 12px; color: var(--ink-soft); text-align: center; }

/* 위쪽 버튼 */
.hud-top { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.hud-top .chip { pointer-events: auto; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251, 247, 239, 0.94);
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(74, 56, 34, 0.1);
}
.chip svg { width: 17px; height: 17px; }

.hint {
  position: fixed;
  top: max(64px, calc(env(safe-area-inset-top) + 52px));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(67, 57, 47, 0.62);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.6s;
}
.hint.fade { opacity: 0; }

/* 아래 동작 버튼 */
.actions {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251, 247, 239, 0.95);
  box-shadow: var(--shadow);
}
.actions button {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 64px;
  padding: 8px 10px 6px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-size: 12px;
}
.actions button:hover { background: var(--paper-2); }
.actions button:active { background: var(--line); }

/* 칸 정보 창 */
.panel {
  position: fixed;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 320px;
  max-height: calc(100% - 140px);
  overflow-y: auto;
  padding: 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}
.panel h2 { margin: 0; font-size: 20px; font-weight: 700; padding-right: 32px; overflow-wrap: anywhere; }
.panel p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--ink-soft); overflow-wrap: anywhere; }
.panel .years { font-size: 13px; }
.panel .message { color: var(--ink); font-size: 15px; }
.panel .close {
  position: absolute;
  top: 12px; right: 12px;
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: 50%;
  background: none;
  color: var(--ink-soft);
}
.panel .close:hover { background: var(--paper-2); }
.panel .row { display: flex; gap: 8px; flex-wrap: wrap; }
.panel .row > * { flex: 1 1 auto; }
.panel .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel form { display: grid; gap: 12px; }
.thumb { width: 96px; height: 96px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); background: var(--paper-2); }
.photo-pick { display: flex; align-items: center; gap: 12px; }
.photo-pick .ghost { display: inline-flex; align-items: center; gap: 6px; }
.count { justify-self: end; font-size: 12px; color: var(--ink-soft); margin-top: -8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 8px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(67, 57, 47, 0.88);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 700px) {
  .panel {
    left: 12px; right: 12px;
    top: auto;
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 74px);
    transform: none;
    width: auto;
    max-height: 52%;
    padding: 16px;
  }
  .hint { top: auto; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 78px); font-size: 12px; }
  .toast { bottom: auto; top: 64px; }
  .actions button { min-width: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast, .hint { transition: none; }
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.pick { position: relative; cursor: pointer; }
.pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
