:root {
  --paper: #f4ecdb;
  --paper-2: #ebe0c8;
  --paper-3: #e2d5b8;
  --ink: #2a251e;
  --ink-2: #6a6152;
  --ink-3: #9a907d;
  --line: rgba(42, 37, 30, 0.14);
  --accent: #b4532a;
  --accent-ink: #fff7ec;
  --shadow: 0 10px 30px rgba(40, 30, 15, 0.22), 0 2px 6px rgba(40, 30, 15, 0.12);
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3e6480; color: var(--ink); font: 15px/1.4 var(--sans);
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

.word { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }

/* top bar */
.top { position: fixed; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; justify-content: space-between;
  align-items: flex-start; pointer-events: none; z-index: 5; }
.top > * { pointer-events: auto; }
.brand { background: var(--paper); border-radius: 14px; padding: 7px 12px 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.brand .word { font-size: 20px; line-height: 1.1; }
.clock { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.pill { background: var(--paper); border: 0; border-radius: 999px; padding: 9px 15px; box-shadow: var(--shadow); font-weight: 600; font-size: 14px; }
.pill.me { display: flex; align-items: center; gap: 7px; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

#minimap { position: fixed; right: 12px; top: calc(max(10px, env(safe-area-inset-top)) + 50px); width: 132px; height: 66px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 4; background: var(--paper); cursor: pointer; touch-action: none; }
@media (min-width: 700px) { #minimap { width: 210px; height: 105px; } }

/* placement banner */
.place { position: fixed; left: 50%; transform: translateX(-50%); top: calc(max(10px, env(safe-area-inset-top)) + 64px); z-index: 6;
  background: var(--ink); color: var(--paper); border-radius: 14px; padding: 10px 14px; display: flex; gap: 12px; align-items: center;
  box-shadow: var(--shadow); font-size: 14px; width: max-content; max-width: calc(100% - 24px); }
.place[hidden] { display: none; }
.place .link { background: none; border: 0; color: #f0c8a8; font-weight: 600; padding: 0; }
@media (max-width: 699px) { .place { top: calc(max(10px, env(safe-area-inset-top)) + 126px); } }

/* toasts */
.toasts { position: fixed; left: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 6; display: flex; flex-direction: column; gap: 6px;
  pointer-events: none; max-width: min(360px, calc(100% - 24px)); }
.toast { background: var(--paper); border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow); font-size: 13.5px; pointer-events: auto;
  animation: tin .35s ease; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.toast.err { background: #5a2a1a; color: #fbe9dc; }
.toast i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* dock */
.dock { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5; display: flex;
  gap: 4px; background: var(--paper); border-radius: 20px; padding: 5px; box-shadow: var(--shadow); }
.dock button { border: 0; background: none; border-radius: 15px; padding: 8px 12px; white-space: nowrap; display: flex; align-items: center; gap: 7px; font-weight: 500; font-size: 14px; }
.dock button:hover { background: var(--paper-2); }
.dock button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.dock svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
@media (max-width: 380px) { .dock button:not(.primary) span { display: none; } }

/* sheet */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--paper); border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px rgba(40,30,15,.28);
  max-height: 86vh; display: flex; flex-direction: column; transform: translateY(105%); transition: transform .32s cubic-bezier(.2,.8,.2,1);
  padding-bottom: env(safe-area-inset-bottom); }
.sheet.open { transform: none; }
.sheet.tall { height: 86vh; }
@media (min-width: 760px) {
  .sheet { left: auto; right: 16px; bottom: 16px; top: 16px; width: 400px; max-height: none; border-radius: 22px; transform: translateX(110%); }
  .sheet.tall { height: auto; }
  .sheet.open { transform: none; }
}
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--paper-3); margin: 8px auto 2px; flex: none; }
@media (min-width: 760px) { .grip { visibility: hidden; } }
.close { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--paper-2); font-size: 20px; line-height: 1; color: var(--ink-2); }
.sheet-body { overflow-y: auto; padding: 6px 18px 22px; -webkit-overflow-scrolling: touch; }

h2 { font-family: var(--serif); font-weight: 600; font-size: 25px; line-height: 1.15; margin: 8px 44px 4px 0; letter-spacing: -0.01em; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); margin: 18px 0 8px; font-weight: 600; }
.sub { color: var(--ink-2); font-size: 14px; margin: 0 0 10px; }
.sub a, .link-btn { color: var(--accent); background: none; border: 0; padding: 0; font-weight: 600; text-decoration: none; cursor: pointer; }
.muted { color: var(--ink-3); }

.portrait { width: 100%; height: 170px; border-radius: 16px; background: var(--paper-2); display: block; margin: 8px 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--paper-2); border-radius: 999px; padding: 4px 10px; font-size: 13px; color: var(--ink); }
.chip.mine { background: var(--accent); color: var(--accent-ink); }
.bar { height: 6px; background: var(--paper-3); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--ink-2); border-radius: 3px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 10px 0; }
.facts div { font-size: 13px; color: var(--ink-2); }
.facts b { display: block; color: var(--ink); font-size: 15px; font-weight: 600; }

.btn { border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600; background: var(--paper-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; }

/* lists */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%; }
.item:last-child { border-bottom: 0; }
.item canvas { width: 64px; height: 48px; flex: none; border-radius: 10px; background: var(--paper-2); }
.item .t { flex: 1; min-width: 0; }
.item .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .o { font-size: 13px; color: var(--ink-2); }
.item .c { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.item .c small { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.tabs { display: flex; gap: 6px; margin: 4px 0 6px; }
.tabs button { border: 0; background: var(--paper-2); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 500; }
.tabs button.on { background: var(--ink); color: var(--paper); }

.ev { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; font-size: 14px; }
.ev .when { color: var(--ink-3); font-size: 12px; width: 54px; flex: none; padding-top: 2px; font-variant-numeric: tabular-nums; }
.ev .what { flex: 1; }

/* editor */
.preview { width: 100%; height: 190px; border-radius: 18px; display: block; background: var(--paper-2); }
.group { margin-top: 6px; }
.slider { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 10px; padding: 6px 0; }
.slider label { font-size: 14px; font-weight: 500; }
.slider .ends { grid-column: 2; display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-top: -4px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--paper-3); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--paper-3); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink);
  margin-top: -8px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); }
input.hue::-webkit-slider-runnable-track { background: var(--hue-track); height: 10px; }
input.hue::-moz-range-track { background: var(--hue-track); height: 10px; }
input.hue::-webkit-slider-thumb { margin-top: -6px; }
.field { width: 100%; border: 1.5px solid var(--line); background: #fbf6ea; border-radius: 12px; padding: 11px 12px; font: inherit; font-size: 16px; color: var(--ink); }
.field:focus { outline: none; border-color: var(--ink-2); }
.key { font-family: ui-monospace, Menlo, monospace; font-size: 26px; letter-spacing: .08em; background: var(--paper-2); border-radius: 14px; padding: 14px; text-align: center; margin: 8px 0; user-select: all; }
.note { font-size: 13px; color: var(--ink-2); margin: 8px 0; }
.err-line { color: #a3361b; font-size: 13.5px; min-height: 1.2em; margin: 6px 0; }
.summary { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }

svg.chart { width: 100%; height: 90px; display: block; }
.lineage { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.lineage .arrow { color: var(--ink-3); }

.loading { position: fixed; inset: 0; background: var(--paper); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--ink-2); transition: opacity .5s; }
.loading .word { font-size: 40px; color: var(--ink); }
.loading.gone { opacity: 0; pointer-events: none; }
