:root {
  --paper: #ece0c5;
  --paper-2: #e4d5b4;
  --paper-hi: #f4ecd9;
  --ink: #33251a;
  --ink-soft: #6b5843;
  --ink-faint: rgba(51, 37, 26, 0.18);
  --rubric: #9a2f22;
  --water: #34474f;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --caps: "Cormorant SC", "Cormorant Garamond", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #d9c9a6; color: var(--ink); }
body { font-family: var(--serif); font-size: 18px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
.vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(80,50,20,0.22) 100%);
  mix-blend-mode: multiply;
}

/* ── Карточки ───────────────────────────────────────────── */
.card {
  position: relative;
  background: var(--paper);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(255,250,235,0.55), transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(150,110,60,0.12), transparent 55%);
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink-soft);
  outline-offset: -6px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.4) inset, 0 18px 40px -18px rgba(60,35,10,0.55), 0 2px 6px rgba(60,35,10,0.18);
  padding: 28px 30px 24px;
  border-radius: 2px;
}
h1, h2 { font-family: var(--caps); font-weight: 600; letter-spacing: 0.04em; margin: 0 0 8px; line-height: 1.1; }
h1 { font-size: 64px; letter-spacing: 0.08em; }
h2 { font-size: 26px; }
.muted { color: var(--ink-soft); }
.small { font-size: 15px; }
.eyebrow { font-family: var(--caps); color: var(--rubric); font-size: 15px; letter-spacing: 0.12em; margin-bottom: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.row.between { justify-content: space-between; }

.btn {
  border: 1px solid var(--ink); background: transparent; padding: 7px 18px 8px;
  font-family: var(--caps); font-weight: 600; font-size: 18px; letter-spacing: 0.04em; cursor: pointer;
  border-radius: 1px; transition: background-color .15s ease, color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: var(--rubric); color: var(--rubric); box-shadow: inset 0 0 0 1px var(--rubric); }
.btn.primary:hover { background: var(--rubric); color: var(--paper-hi); }
.btn:focus-visible, .link:focus-visible, .type:focus-visible, .speeds button:focus-visible, input:focus-visible, .pill:focus-visible {
  outline: 2px solid var(--rubric); outline-offset: 2px;
}
.link { border: 0; background: none; padding: 4px 0; cursor: pointer; color: var(--ink-soft); font-style: italic; font-size: 17px; }
.link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.link.danger:hover { color: var(--rubric); }

input {
  background: rgba(255,250,235,0.55); border: 0; border-bottom: 1px solid var(--ink);
  padding: 6px 4px; font-size: 20px; min-width: 0; flex: 1; border-radius: 0;
}
.field { display: block; margin-top: 14px; }
.field span { display: block; font-family: var(--caps); font-size: 15px; color: var(--ink-soft); letter-spacing: 0.06em; }
.field input { width: 100%; font-style: italic; font-weight: 600; }
.err { color: var(--rubric); font-style: italic; min-height: 1.2em; font-size: 16px; }

/* ── Экраны ─────────────────────────────────────────────── */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; pointer-events: none; }
.screen > .card { pointer-events: auto; }
.screen.dock { place-items: end start; padding: 24px; }
.screen.dock > .card { width: min(460px, 100%); }
#screen-title { background: rgba(60, 40, 15, 0.12); pointer-events: auto; }
.title-card { width: min(520px, 100%); text-align: center; padding: 40px 40px 28px; animation: rise .6s ease-out both; }
.ornament { color: var(--rubric); font-size: 28px; line-height: 1; margin-bottom: 6px; }
.lede { font-size: 20px; font-style: italic; color: var(--ink-soft); margin: 4px 0 22px; text-wrap: pretty; }
.title-card .actions { display: flex; justify-content: center; }
.keyin { margin-top: 18px; text-align: left; }
.keyin summary { cursor: pointer; font-style: italic; color: var(--ink-soft); text-align: center; list-style: none; }
.keyin summary::-webkit-details-marker { display: none; }
.keyin summary:hover { color: var(--ink); }
.status { margin-top: 14px; font-size: 15px; color: var(--ink-soft); font-style: italic; min-height: 1.2em; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.dock > .card { animation: rise .35s ease-out both; }

.types { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0 4px; }
.type {
  text-align: left; border: 1px solid var(--ink-faint); background: rgba(255,250,235,0.35);
  padding: 10px 12px 12px; cursor: pointer; border-radius: 1px; transition: border-color .15s, background-color .15s;
  display: grid; grid-template-columns: 44px 1fr; gap: 2px 10px; align-items: center;
}
.type svg { grid-row: span 2; width: 44px; height: 38px; }
.type b { font-family: var(--caps); font-size: 19px; font-weight: 600; }
.type small { grid-column: 1 / -1; font-size: 14.5px; color: var(--ink-soft); line-height: 1.3; margin-top: 4px; }
.type:hover { border-color: var(--ink); background: rgba(255,250,235,0.7); }
.type:disabled { opacity: .4; cursor: not-allowed; }
.desc { font-size: 18.5px; text-wrap: pretty; margin: 8px 0 0; }
.desc::first-letter { font-family: var(--caps); color: var(--rubric); font-size: 2.1em; float: left; line-height: .9; margin: 4px 6px 0 0; }

/* ── HUD ────────────────────────────────────────────────── */
.hud {
  position: fixed; top: 0; left: 0; right: 0; display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: start; gap: 16px; padding: 14px 18px; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-left {
  justify-self: start; background: rgba(236,224,197,0.88); border: 1px solid var(--ink);
  outline: 1px solid var(--ink-faint); outline-offset: -4px; padding: 8px 16px 9px; min-width: 230px;
  box-shadow: 0 8px 22px -12px rgba(60,35,10,.5);
}
.realm { font-family: var(--caps); font-size: 24px; font-weight: 700; letter-spacing: 0.05em; line-height: 1.1; }
.date { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.subdate { font-size: 15px; color: var(--ink-soft); font-style: italic; }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.speeds {
  display: flex; background: rgba(236,224,197,0.9); border: 1px solid var(--ink);
  box-shadow: 0 8px 22px -12px rgba(60,35,10,.5);
}
.speeds button {
  border: 0; border-left: 1px solid var(--ink-faint); background: transparent; cursor: pointer;
  min-width: 46px; height: 36px; padding: 0 10px; font-family: var(--caps); font-weight: 600; font-size: 17px;
  font-variant-numeric: tabular-nums; display: grid; place-items: center; transition: background-color .12s, color .12s;
}
.speeds button:first-child { border-left: 0; }
.speeds button:hover { background: rgba(51,37,26,0.08); }
.speeds button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.speeds button[data-speed="0"][aria-pressed="true"] { background: var(--rubric); }
.speed-hint { font-size: 14.5px; font-style: italic; color: var(--ink-soft); background: rgba(236,224,197,0.75); padding: 0 8px; }
.hud-right { justify-self: end; }
.pill {
  border: 1px solid var(--ink); background: rgba(236,224,197,0.9); padding: 5px 14px 6px; cursor: pointer;
  font-size: 16px; display: flex; gap: 8px; align-items: center; box-shadow: 0 8px 22px -12px rgba(60,35,10,.5);
}
.pill:hover { background: var(--paper-hi); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #5b7a4a; }
.pill.off .dot { background: var(--rubric); }

.scalebar { position: fixed; left: 22px; bottom: 18px; pointer-events: none; }
.scalebar .bar { display: flex; height: 7px; border: 1px solid var(--ink); }
.scalebar .bar span { flex: 1; }
.scalebar .bar span:first-child { background: var(--ink); }
.scalebar .label { font-size: 14px; font-style: italic; margin-top: 2px; }
.compass { position: fixed; right: 20px; bottom: 16px; width: 74px; height: 74px; opacity: .85; pointer-events: none; }

.tip {
  position: fixed; z-index: 5; pointer-events: none; background: rgba(244,236,217,0.97); border: 1px solid var(--ink);
  padding: 7px 11px 8px; font-size: 15.5px; line-height: 1.32; max-width: 260px;
  box-shadow: 0 8px 20px -10px rgba(60,35,10,.55);
}
.tip b { font-family: var(--caps); font-size: 17px; font-weight: 600; }
.tip .k { color: var(--ink-soft); }

dialog.card { width: min(480px, calc(100% - 32px)); color: var(--ink); }
dialog::backdrop { background: rgba(50, 30, 10, 0.3); }
.bigkey {
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 19px; white-space: nowrap; letter-spacing: 0.02em;
  background: var(--paper-hi); border: 1px dashed var(--ink); padding: 10px 14px; margin: 12px 0 6px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; user-select: all;
}

.loading {
  position: fixed; inset: 0; display: grid; place-items: center; align-content: center; gap: 12px;
  font-style: italic; font-size: 22px; color: var(--ink-soft); pointer-events: none;
}
.quill { width: 48px; height: 2px; background: var(--ink); animation: write 1.1s ease-in-out infinite; transform-origin: left; }
@keyframes write { 0% { transform: scaleX(0.1); } 50% { transform: scaleX(1); } 100% { transform: scaleX(0.1); transform-origin: right; } }

@media (max-width: 720px) {
  h1 { font-size: 46px; }
  .hud { grid-template-columns: 1fr; justify-items: start; }
  .hud-center { align-items: flex-start; }
  .hud-right { justify-self: start; }
  .screen.dock { place-items: end center; padding: 12px; }
  .compass { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
