/* Inkwell — base: themes, typography, shell */
:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, Cambria, "Times New Roman", serif;
  --display: "Bodoni MT", Didot, "Didot LT STD", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --r: 14px;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='turbulence' baseFrequency='.012 .09' numOctaves='2' seed='3'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

/* ---------- themes ---------- */
body[data-theme="midnight"] {
  --bg0: #070d22; --bg1: #0b1430; --bg2: #14204a; --leather: #1a2858; --leather-2: #111c42;
  --text: #f1e8d2; --muted: #a9b4d2; --brass: #c9a24a; --brass-hi: #f6e2a4; --brass-lo: #7a5a1e;
  --stitch: rgba(240, 213, 138, .5); --panel: rgba(13, 22, 54, .82); --line: rgba(240, 213, 138, .18);
  --accent: #e8b75a; --danger: #d0573e; --felt: #0f2a2a; --lamp: rgba(255, 210, 130, .16); --ok: #8fd19e;
  --paper-card: #f3ecdb; --paper-ink: #1f2747;
}
body[data-theme="ivory"] {
  --bg0: #d9ccb2; --bg1: #efe6d2; --bg2: #e6d9bd; --leather: #7b4a2a; --leather-2: #5e3519;
  --text: #2a1f15; --muted: #6b5a47; --brass: #a9812f; --brass-hi: #f2dc9c; --brass-lo: #6b4e17;
  --stitch: rgba(255, 236, 190, .65); --panel: rgba(255, 250, 238, .86); --line: rgba(90, 60, 20, .2);
  --accent: #9b3b1f; --danger: #b2361f; --felt: #2f4a3a; --lamp: rgba(255, 240, 200, .5); --ok: #2f7a45;
  --paper-card: #fffaf0; --paper-ink: #2a1f15;
}
body[data-theme="oxblood"] {
  --bg0: #160607; --bg1: #2a0f12; --bg2: #3d161a; --leather: #5a1c21; --leather-2: #3e1115;
  --text: #f4e6d3; --muted: #d0aea6; --brass: #caa04e; --brass-hi: #f5dfa0; --brass-lo: #6f4f18;
  --stitch: rgba(245, 214, 150, .5); --panel: rgba(46, 14, 17, .84); --line: rgba(245, 214, 150, .18);
  --accent: #f0b864; --danger: #ff7a5c; --felt: #23301f; --lamp: rgba(255, 190, 120, .15); --ok: #a6d99b;
  --paper-card: #f4ead6; --paper-ink: #3a1418;
}
body[data-theme="sumi"] {
  --bg0: #060607; --bg1: #121214; --bg2: #1c1c20; --leather: #222226; --leather-2: #18181b;
  --text: #ece8de; --muted: #a8a49a; --brass: #c23b22; --brass-hi: #ee8a6c; --brass-lo: #6b1d10;
  --stitch: rgba(236, 232, 222, .28); --panel: rgba(24, 24, 27, .9); --line: rgba(236, 232, 222, .14);
  --accent: #e0553a; --danger: #ff6d50; --felt: #1d2622; --lamp: rgba(255, 255, 255, .05); --ok: #b8d8a8;
  --paper-card: #f6f1e4; --paper-ink: #16161b;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--serif); font-size: 17px; line-height: 1.55; color: var(--text);
  background:
    radial-gradient(1200px 700px at 12% -10%, var(--lamp), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(0, 0, 0, .45), transparent 60%),
    var(--noise),
    linear-gradient(160deg, var(--bg1), var(--bg0));
  background-attachment: fixed, fixed, scroll, fixed;
  overflow-x: hidden;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  transition: background-color .6s var(--ease), color .4s var(--ease);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--brass-hi); }
img, svg, canvas { max-width: 100%; }
kbd {
  font-family: var(--mono); font-size: .78em; padding: .05em .45em; border-radius: 5px;
  background: linear-gradient(var(--brass-hi), var(--brass)); color: #2a1d08;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25), 0 1px 1px rgba(0, 0, 0, .3);
}
code { font-family: var(--mono); font-size: .88em; background: rgba(0, 0, 0, .08); padding: .05em .35em; border-radius: 4px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: -1px; padding: 0; border: 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 3px; border-radius: 6px; }

.skip { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 16px; background: var(--brass); color: #1a1206; border-radius: 10px; transition: top .2s; }
.skip:focus { top: 12px; }

/* ---------- leather & paper surfaces ---------- */
.leather {
  position: relative;
  background: var(--grain), var(--noise), linear-gradient(170deg, var(--leather), var(--leather-2));
  border-radius: var(--r);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 -1px 0 rgba(0, 0, 0, .4) inset, 0 12px 30px rgba(0, 0, 0, .35);
  outline: 1.5px dashed var(--stitch); outline-offset: -8px;
  padding: 20px;
}
.paper-card {
  background: radial-gradient(120% 90% at 20% 0%, rgba(255, 255, 255, .5), transparent 60%), var(--noise), var(--paper-card);
  color: var(--paper-ink); border-radius: 6px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .2), 0 18px 40px rgba(0, 0, 0, .35);
  padding: 28px;
}
.paper-card a { color: #8a3b14; }
.section-title { font-family: var(--display); font-weight: 600; font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.3rem); margin: 0 0 .35em; letter-spacing: .01em; font-style: italic; }
.section-title.dark { color: var(--paper-ink); }

/* ---------- brass controls ---------- */
.brass-btn {
  --b1: var(--brass-hi); --b2: var(--brass); --b3: var(--brass-lo);
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid rgba(0, 0, 0, .45);
  background: linear-gradient(180deg, var(--b1) 0%, var(--b2) 48%, var(--b3) 100%);
  color: #1d1406; font-weight: 600; font-size: .92rem; letter-spacing: .02em; text-decoration: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), inset 0 -2px 0 rgba(0, 0, 0, .25), 0 3px 8px rgba(0, 0, 0, .35);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), filter .2s;
  -webkit-tap-highlight-color: transparent; white-space: nowrap; position: relative; overflow: hidden;
}
.brass-btn::after {
  content: ""; position: absolute; inset: 0; background: linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, .55) 50%, transparent 70%);
  transform: translateX(-120%); transition: transform .7s var(--ease); pointer-events: none;
}
.brass-btn:hover::after, .brass-btn:focus-visible::after { transform: translateX(120%); }
.brass-btn:hover { filter: brightness(1.06); color: #1d1406; }
.brass-btn:active { transform: translateY(1px) scale(.98); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .3); }
.brass-btn:disabled { filter: grayscale(.7) brightness(.8); cursor: not-allowed; }
.brass-btn.small { min-height: 44px; padding: 0 12px; font-size: .84rem; }
.brass-btn.icon-only { width: 44px; padding: 0; }
.brass-btn.icon-only svg { width: 22px; height: 22px; }
.brass-btn.wide { width: 100%; }
.brass-btn.danger { --b1: #f3b4a2; --b2: #c5553a; --b3: #6c2213; color: #200803; }
.brass-btn.on { --b1: #fff1c4; --b2: #e2b955; --b3: #8f6a26; box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35), 0 0 0 2px rgba(246, 226, 164, .35); }
body[data-theme="sumi"] .brass-btn { color: #fff6ef; text-shadow: 0 1px 0 rgba(0, 0, 0, .35); }
body[data-theme="sumi"] .brass-btn.danger { color: #200803; }

.brass-select, .title-input {
  min-height: 44px; border-radius: 11px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .22); color: var(--text); padding: 0 12px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35);
}
body[data-theme="ivory"] .brass-select, body[data-theme="ivory"] .title-input { background: rgba(255, 255, 255, .55); }
.brass-select option { background: var(--bg2); color: var(--text); }
.brass-select.small { min-height: 44px; font-size: .9rem; }
.title-input { font-family: var(--display); font-style: italic; font-size: 1.15rem; min-width: 0; }
.title-input.small { font-size: 1rem; font-family: var(--serif); font-style: normal; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; border: 1px solid rgba(0, 0, 0, .45);
  background: radial-gradient(circle at 35% 30%, var(--brass-hi), var(--brass) 55%, var(--brass-lo)); color: #1d1406;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 3px 8px rgba(0, 0, 0, .35); transition: transform .2s var(--spring);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(.92); }
.icon-btn .snd-on { display: none; }
.icon-btn.on .snd-on { display: inline; }
.icon-btn.on .snd-off { display: none; }
.icon-btn.remembered:not(.on) { animation: nudge 2.4s ease-in-out 2; }
@keyframes nudge { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-10deg); } 90% { transform: rotate(10deg); } 95% { transform: rotate(-5deg); } }

.field { display: grid; gap: 4px; font-size: .86rem; color: var(--muted); }
.field > span { display: flex; justify-content: space-between; gap: 8px; }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }
.field.inline { display: inline-flex; align-items: center; gap: 8px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: .88rem; color: var(--muted); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brass); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 4px; background: linear-gradient(90deg, var(--brass-lo), var(--brass)); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .5); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 4px; background: linear-gradient(90deg, var(--brass-lo), var(--brass)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -9px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .5); background: radial-gradient(circle at 35% 30%, #fff6d6, var(--brass) 55%, var(--brass-lo)); box-shadow: 0 2px 5px rgba(0, 0, 0, .45); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .5); background: radial-gradient(circle at 35% 30%, #fff6d6, var(--brass) 55%, var(--brass-lo)); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) clamp(12px, 3vw, 32px) 10px;
  background: linear-gradient(180deg, rgba(0, 0, 0, .35), rgba(0, 0, 0, .15)), var(--noise), var(--leather-2);
  border-bottom: 1px solid rgba(0, 0, 0, .5);
  box-shadow: 0 1px 0 var(--line) inset, 0 6px 20px rgba(0, 0, 0, .35);
}
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 4px; border-bottom: 1.5px dashed var(--stitch); pointer-events: none; opacity: .7; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-height: 44px; }
.brand-ink { width: 42px; height: 42px; flex: none; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .45)); transition: transform .4s var(--spring); }
.brand:hover .brand-ink { transform: rotate(-8deg) translateY(-2px); }
.brand-ink-level { animation: slosh 5s ease-in-out infinite; transform-origin: 24px 36px; }
@keyframes slosh { 0%, 100% { transform: skewY(0); } 25% { transform: skewY(-3deg); } 75% { transform: skewY(3deg); } }
.brand-text { display: grid; line-height: 1.05; }
.brand-name { font-family: var(--display); font-style: italic; font-weight: 700; font-size: 1.55rem; letter-spacing: .01em;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass) 60%, var(--brass-lo)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-text small { font-size: .72rem; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; }
.mainnav { display: flex; gap: 4px; margin-left: auto; }
.mainnav a {
  position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: .98rem; letter-spacing: .02em; transition: background .25s, color .25s;
}
.mainnav a::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: 7px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--brass-hi), transparent); transform: scaleX(0); transition: transform .35s var(--ease);
}
.mainnav a:hover { background: rgba(255, 255, 255, .06); color: var(--brass-hi); }
.mainnav a[aria-current="page"] { color: var(--brass-hi); }
.mainnav a[aria-current="page"]::after, .mainnav a:hover::after { transform: scaleX(1); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.save-state { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); min-width: 0; max-width: 220px; }
.save-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blot { width: 14px; height: 14px; flex: none; border-radius: 50% 45% 55% 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(143, 209, 158, .15); transition: background .3s; }
.save-state.saving .blot { background: var(--brass); animation: blotPulse .7s ease-in-out infinite; }
.save-state.err .blot { background: var(--danger); }
@keyframes blotPulse { 50% { transform: scale(1.35) rotate(40deg); border-radius: 40% 60% 45% 55%; } }
.nav-toggle { display: none; width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .2); padding: 12px 11px; flex-direction: column; justify-content: space-between; }
.nav-toggle span { display: block; height: 2px; border-radius: 2px; background: var(--brass-hi); transition: transform .3s var(--ease), opacity .2s; }
body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }

main { padding: clamp(12px, 2.4vw, 28px) clamp(10px, 3vw, 32px) 30px; max-width: 1760px; margin: 0 auto; outline: none; }
.view.enter { animation: viewIn .55s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(14px) scale(.995); filter: blur(3px); } to { opacity: 1; transform: none; filter: none; } }

/* ---------- footer ---------- */
.site-footer { padding: 26px clamp(14px, 3vw, 32px) calc(26px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(0, 0, 0, .4); background: linear-gradient(0deg, rgba(0, 0, 0, .35), transparent); text-align: center; }
.foot-inner { max-width: 980px; margin: 0 auto; display: grid; gap: 6px; }
.foot-inner p { margin: 0; }
.gratitude { font-style: italic; color: var(--muted); }

/* ---------- toast & modal ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 90; max-width: min(560px, calc(100vw - 24px));
  transform: translate(-50%, 140%) rotate(-1deg); opacity: 0; pointer-events: none;
  padding: 12px 18px; border-radius: 10px; color: var(--paper-ink); font-size: .95rem;
  background: var(--noise), var(--paper-card); box-shadow: 0 14px 30px rgba(0, 0, 0, .45); border-left: 5px solid var(--brass);
  transition: transform .45s var(--spring), opacity .3s;
}
.toast.show { transform: translate(-50%, 0) rotate(-.5deg); opacity: 1; }
.toast.err { border-left-color: var(--danger); }
.modal { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; padding: 18px; background: rgba(5, 8, 20, .6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fadeIn .25s; }
.modal-card { max-width: 440px; width: 100%; animation: cardIn .4s var(--spring); }
.modal-msg { font-size: 1.08rem; margin: 0 0 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(20px) rotate(-2deg) scale(.95); } }
.noscript { text-align: center; padding: 30px; }

/* ---------- intro ---------- */
.intro { position: fixed; inset: 0; z-index: 99; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, var(--bg2), var(--bg0)); transition: opacity .6s var(--ease), visibility .6s; animation: introAuto 0s linear 3.6s forwards; }
.intro.done { opacity: 0; visibility: hidden; }
@keyframes introAuto { to { opacity: 0; visibility: hidden; pointer-events: none; } }
.intro-card { width: min(560px, 88vw); padding: 26px 20px 18px; text-align: center; border-radius: 6px; background: var(--noise), var(--paper-card); box-shadow: 0 30px 60px rgba(0, 0, 0, .55); transform: rotate(-1.5deg); animation: cardIn .7s var(--spring); }
.intro-svg { width: 100%; height: auto; }
.intro-word { font-family: var(--display); font-style: italic; font-weight: 700; font-size: 120px; fill: transparent; stroke: #1d2b4f; stroke-width: 1.6; stroke-dasharray: 900; stroke-dashoffset: 900; animation: sign 1.5s var(--ease) .15s forwards, inkfill .5s ease 1.35s forwards; }
.intro-flourish { fill: none; stroke: #1d2b4f; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 520; stroke-dashoffset: 520; animation: sign .8s var(--ease) 1.2s forwards; }
@keyframes sign { to { stroke-dashoffset: 0; } }
@keyframes inkfill { to { fill: #1d2b4f; } }
.intro-sub { margin: 4px 0 0; color: #6b5a47; font-style: italic; letter-spacing: .08em; }

@media (max-width: 1100px) {
  .nav-toggle { display: flex; order: 3; }
  .top-actions { margin-left: auto; }
  .mainnav {
    position: fixed; left: 10px; right: 10px; top: calc(70px + env(safe-area-inset-top)); z-index: 45;
    flex-direction: column; gap: 2px; padding: 12px; border-radius: 16px;
    background: var(--noise), linear-gradient(170deg, var(--leather), var(--leather-2));
    box-shadow: 0 20px 40px rgba(0, 0, 0, .5); outline: 1.5px dashed var(--stitch); outline-offset: -7px;
    transform: translateY(-12px) scale(.98); opacity: 0; visibility: hidden; transition: transform .35s var(--spring), opacity .25s, visibility .25s;
  }
  body.nav-open .mainnav { transform: none; opacity: 1; visibility: visible; }
  .mainnav a { min-height: 50px; font-size: 1.08rem; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .brand-text small { display: none; }
  .brand-name { font-size: 1.3rem; }
  .save-state { display: none; }
  .topbar { gap: 8px; }
  #themeSel { max-width: 120px; padding: 0 6px; font-size: .85rem; }
}
@media (max-width: 380px) { #themeSel { max-width: 96px; } .brand-ink { width: 36px; height: 36px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .intro { display: none; }
}
