:root {
  --bg: #0f1526;
  --panel: #161c2c;
  --panel-glass: rgba(22, 28, 44, 0.84);
  --card: #1e2436;
  --line: rgba(255, 255, 255, 0.12);
  --ink: #f4eee2;
  --mute: #a9b0c2;
  --gold: #d9b45e;
  --danger: #ff8f8f;
  --tonal: rgba(255, 255, 255, 0.08);
  --tonal-hover: rgba(255, 255, 255, 0.14);
  --on-primary: #121726;
  --radius: 16px;
  --display: 'Instrument Serif', Georgia, serif;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) { --bg: #0f1526; }
}
:root[data-theme='dark'] { --bg: #0f1526; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.stage { position: fixed; inset: 0; touch-action: none; }
.stage canvas { display: block; width: 100%; height: 100%; }

.title {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 28px); left: 16px; right: 16px;
  text-align: center; pointer-events: none;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
}
.logo { display: block; width: auto; height: 26px; margin: 0 auto 10px; filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.55)); }
@media (min-width: 700px) { .title .logo { height: 32px; } }
.title h1 { margin: 0; font-family: var(--display); font-style: italic; font-weight: 400; font-size: clamp(30px, 5vw, 48px); line-height: 1.05; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel-glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); font-size: 14px; font-weight: 500;
}
.chip:hover { background: rgba(32, 38, 56, 0.9); }
.zoom { position: fixed; right: 16px; top: calc(env(safe-area-inset-top, 0px) + 116px); }

.bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 20px); width: min(560px, calc(100% - 32px));
  padding: 14px 12px 12px; border: 1px solid var(--line); border-radius: 24px;
  background: var(--panel-glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  display: flex; flex-direction: column; gap: 12px;
}
.hint { margin: 0; text-align: center; font-size: 13px; color: #b7bdcc; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 20px; border: 0; border-radius: var(--radius);
  font-size: 16px; font-weight: 600; text-decoration: none; transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--ink); color: var(--on-primary); }
.btn.primary:hover:not(:disabled) { background: #fffaf0; }
.btn.tonal { background: var(--tonal); color: var(--ink); font-weight: 500; }
.btn.tonal:hover { background: var(--tonal-hover); }
.btn.sm { height: 40px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn.block { width: 100%; }
.grow { flex: 1 1 0; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.center { justify-content: center; text-align: center; }
.muted { color: var(--mute); margin: 0; }
.small { font-size: 13px; }

.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0; border: 0; border-radius: 12px; background: var(--tonal);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--tonal-hover); }
.icon-btn.lg { width: 52px; height: 52px; border-radius: var(--radius); }
.text-btn { height: 44px; padding: 0 12px 0 4px; border: 0; background: none; display: inline-flex; align-items: center; gap: 4px; font-size: 15px; }

.pill {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top, 0px) + 120px); margin: 0;
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.place-row { display: flex; align-items: center; gap: 12px; padding: 0 2px; }
.place-thumb { width: 48px; height: 48px; object-fit: contain; }
.place-kind { margin: 0 0 2px; font-weight: 600; font-size: 15px; }

.scrim { position: fixed; inset: 0; background: rgba(6, 9, 18, 0.62); }

.sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0;
  width: min(600px, 100%); max-height: calc(100% - 40px); overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 20px calc(var(--safe-b) + 28px); border-radius: 28px 28px 0 0;
  border-top: 1px solid var(--line); background: var(--panel);
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@media (min-width: 700px) {
  .sheet { bottom: 50%; transform: translate(-50%, 50%); border-radius: 28px; border: 1px solid var(--line); max-height: calc(100% - 64px); animation: fade 0.2s ease; }
}
@keyframes rise { from { transform: translate(-50%, 40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.view { display: flex; flex-direction: column; gap: 22px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.display { margin: 0; font-family: var(--display); font-weight: 400; font-size: 34px; line-height: 1.1; }

.kind-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.kind {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 0 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 20px; background: var(--card); overflow: hidden; text-align: left;
}
.kind:hover { border-color: var(--gold); }
.kind img { width: 100%; aspect-ratio: 1 / 0.85; object-fit: contain; background: #202638; margin-bottom: 10px; }
.kind > span { padding: 0 14px; }
.kind-name { font-size: 16px; font-weight: 600; }

.stage-card { border-radius: 24px; background: var(--card); padding: 12px 16px 20px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.preview { width: 200px; height: 200px; }
.paint, .photo { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.pad { width: min(280px, 72vw); aspect-ratio: 1; border-radius: 50%; touch-action: none; cursor: crosshair; box-shadow: inset 0 0 0 1px var(--line); }

.options { display: flex; flex-direction: column; gap: 22px; }
.group-label { margin: 0 0 12px; font-size: 14px; color: var(--mute); }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 12px; font-size: 14px; color: var(--mute); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.swatch.lg { width: 44px; height: 44px; }
.swatch[aria-checked='true'] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink); }
.segment { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { height: 44px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--tonal); font-size: 15px; font-weight: 500; }
.seg.sm { height: 40px; padding: 0 14px; font-size: 14px; }
.seg[aria-checked='true'] { background: var(--ink); color: var(--on-primary); }

.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 14px; color: var(--mute); }
.field input, .field textarea {
  width: 100%; padding: 14px 16px; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 14px;
  background: var(--card); font-size: 16px; resize: none;
}
.field input::placeholder, .field textarea::placeholder { color: #8a91a3; }
.error { margin: 0; color: var(--danger); font-size: 14px; }

.card {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(360px, calc(100% - 48px));
  padding: 24px 22px 20px; border-radius: 28px; border: 1px solid var(--line); background: var(--panel);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55); display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center;
  animation: fade 0.2s ease;
}
.card .row { width: 100%; }
.note-thumb { width: 140px; height: 140px; object-fit: contain; }
.note {
  margin: 0; width: 100%; padding: 16px; border-radius: 18px; background: var(--card);
  font-family: var(--display); font-style: italic; font-size: 22px; line-height: 1.3; overflow-wrap: anywhere;
}

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 20px); transform: translate(-50%, -20px);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: var(--ink); color: var(--on-primary);
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading {
  position: fixed; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; background: var(--bg);
  font-family: var(--display); font-style: italic; font-size: 24px; transition: opacity 0.6s; z-index: 30;
}
.loading .logo { height: 40px; margin-bottom: 8px; }
.loading p { margin: 0; animation: breathe 1.6s ease-in-out infinite; }
.loading.done { opacity: 0; pointer-events: none; }
@keyframes breathe { 50% { opacity: 0.45; } }
.noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; margin: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
