/* ==========================================================================
   Kotoba — design system
   ========================================================================== */

:root {
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif JP", "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg:        #f4f2ed;
  --bg-alt:    #eceae3;
  --surface:   #fbfaf7;
  --surface-2: #f7f5f0;
  --ink:       #1a1815;
  --ink-2:     #4a453d;
  --ink-3:     #837c71;
  --ink-4:     #a9a196;
  --line:      #e2ddd3;
  --line-2:    #d3ccbf;
  --accent:    #2d3f5e;
  --accent-ink:#ffffff;
  --accent-sub:#e8ecf3;
  --danger:    #8f3430;
  --danger-sub:#f6ebe9;
  --warn:      #8a6a24;
  --warn-sub:  #f6f0e2;
  --ok:        #3c6148;

  --r-s: 6px;
  --r-m: 10px;
  --r-l: 16px;
  --shadow-s: 0 1px 2px rgba(26, 24, 21, .05);
  --shadow-m: 0 4px 20px -8px rgba(26, 24, 21, .18);
  --shadow-l: 0 18px 48px -20px rgba(26, 24, 21, .34);

  --header-h: 56px;
  --maxw: 720px;
  --dur: .22s;
  --ease: cubic-bezier(.22, .8, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #131211;
    --bg-alt:    #191816;
    --surface:   #1c1b19;
    --surface-2: #232220;
    --ink:       #ece7dd;
    --ink-2:     #c3bcaf;
    --ink-3:     #918a7e;
    --ink-4:     #6d675d;
    --line:      #2f2d29;
    --line-2:    #403d38;
    --accent:    #9db4dc;
    --accent-ink:#12161f;
    --accent-sub:#232a37;
    --danger:    #d98d88;
    --danger-sub:#2e2220;
    --warn:      #d3b271;
    --warn-sub:  #2b2519;
    --ok:        #8dbb9d;
    --shadow-s: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-m: 0 4px 20px -8px rgba(0, 0, 0, .6);
    --shadow-l: 0 18px 48px -20px rgba(0, 0, 0, .8);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.75;
  font-feature-settings: "palt" 1;
  letter-spacing: .012em;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
  word-break: normal;
  line-break: strict;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.5; letter-spacing: .01em; }
p { margin: 0; }
a { color: inherit; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
img { max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.hidden { display: none !important; }

/* ── header ─────────────────────────────────────────── */
.hd {
  position: sticky; top: 0; z-index: 50;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 12px;
  padding-inline: max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.5) blur(14px);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: baseline; gap: 9px;
  text-decoration: none; margin-right: auto; flex: none;
}
.brand__mark {
  font-family: var(--serif); font-size: 19px; font-weight: 600;
  letter-spacing: .1em; line-height: 1; white-space: nowrap;
}
.brand__sub {
  font-size: 9.5px; letter-spacing: .26em; color: var(--ink-4);
  text-transform: uppercase; white-space: nowrap;
}

.hd__nav {
  display: flex; align-items: center; gap: 2px;
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none;
  margin-right: calc(-1 * max(16px, env(safe-area-inset-left)));
  padding-right: max(16px, env(safe-area-inset-left));
}
.hd__nav::-webkit-scrollbar { display: none; }
.hd__link {
  font-size: 13px; color: var(--ink-3); text-decoration: none;
  padding: 7px 10px; border-radius: var(--r-s); white-space: nowrap;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.hd__link:hover { color: var(--ink); background: var(--bg-alt); }
.hd__link.is-on { color: var(--ink); font-weight: 600; }
.hd__link--admin { color: var(--accent); }

/* ── layout ─────────────────────────────────────────── */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px max(18px, env(safe-area-inset-left)) 140px;
}
.wrap--wide { max-width: 1180px; }
.wrap--narrow { max-width: 480px; padding-bottom: 60px; }

.lede { margin-bottom: 30px; }
.lede h1 {
  font-family: var(--serif); font-size: clamp(23px, 6.2vw, 30px);
  letter-spacing: .03em; line-height: 1.45;
}
.lede p { margin-top: 9px; color: var(--ink-3); font-size: 13.5px; line-height: 1.85; }

/* ── section ────────────────────────────────────────── */
.sec { margin-bottom: 14px; }
.sec__hd {
  display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 12px; padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}
.sec__n {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .16em;
  color: var(--ink-4); padding-top: 2px;
}
.sec__t { font-size: 14.5px; font-weight: 600; letter-spacing: .04em; }
.sec__note { margin-left: auto; font-size: 11.5px; color: var(--ink-4); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 18px 16px;
  box-shadow: var(--shadow-s);
}
.card + .card { margin-top: 12px; }

/* ── form ───────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field__label {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  margin-bottom: 7px; letter-spacing: .04em;
}
.field__hint { font-size: 11.5px; color: var(--ink-4); font-weight: 400; letter-spacing: 0; }
.field__err { display: block; margin-top: 6px; font-size: 12px; color: var(--danger); }
.req {
  font-size: 9.5px; letter-spacing: .08em; color: var(--danger);
  border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; line-height: 1.5;
}
.opt {
  font-size: 9.5px; letter-spacing: .08em; color: var(--ink-4);
  border: 1px solid var(--line-2); border-radius: 3px; padding: 0 4px; line-height: 1.5;
}

.input, .select, .textarea {
  width: 100%; font: inherit; font-size: 16px; /* iOSズーム防止 */
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line-2); border-radius: var(--r-m);
  padding: 11px 13px; line-height: 1.6;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  -webkit-appearance: none; appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.textarea { resize: vertical; min-height: 84px; }

.select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) calc(50% + 1px), calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.row { display: grid; gap: 12px; }
@media (min-width: 560px) {
  .row--2 { grid-template-columns: 1fr 1fr; }
  .row--3 { grid-template-columns: repeat(3, 1fr); }
  .row--21 { grid-template-columns: 2fr 1fr; }
}

/* ── segmented control ──────────────────────────────── */
.seg { display: flex; gap: 4px; background: var(--bg-alt); border: 1px solid var(--line); border-radius: var(--r-m); padding: 3px; }
.seg__b {
  flex: 1; font: inherit; font-size: 12.5px; font-weight: 500;
  color: var(--ink-3); background: none; border: 0; cursor: pointer;
  padding: 8px 6px; border-radius: 7px; white-space: nowrap;
  transition: all var(--dur) var(--ease);
}
.seg__b:hover { color: var(--ink); }
.seg__b[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-s); }

/* ── chips ──────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font: inherit; font-size: 12.5px; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: 100px; padding: 6px 13px; cursor: pointer;
  transition: all var(--dur) var(--ease); white-space: nowrap;
}
.chip:hover { border-color: var(--ink-4); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 500; }
.chip--x { display: inline-flex; align-items: center; gap: 6px; }
.chip__x { color: var(--ink-4); font-size: 15px; line-height: 1; }

/* ── toggle ─────────────────────────────────────────── */
.tg { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; padding: 11px 0; }
.tg + .tg { border-top: 1px solid var(--line); }
.tg__box { position: absolute; opacity: 0; pointer-events: none; }
.tg__sw {
  flex: none; width: 42px; height: 25px; border-radius: 100px;
  background: var(--line-2); border: 1px solid transparent; position: relative;
  transition: background var(--dur) var(--ease); margin-top: 1px;
}
.tg__sw::after {
  content: ""; position: absolute; inset: 2px auto 2px 2px; width: 19px;
  border-radius: 100px; background: var(--surface); box-shadow: var(--shadow-s);
  transition: transform var(--dur) var(--ease);
}
.tg__box:checked + .tg__sw { background: var(--accent); }
.tg__box:checked + .tg__sw::after { transform: translateX(17px); }
.tg__box:focus-visible + .tg__sw { outline: 2px solid var(--accent); outline-offset: 2px; }
.tg__txt { min-width: 0; }
.tg__t { display: block; font-size: 13.5px; font-weight: 500; }
.tg__d { display: block; font-size: 11.5px; color: var(--ink-3); line-height: 1.7; margin-top: 2px; }

/* ── range ──────────────────────────────────────────── */
.rng { display: flex; align-items: center; gap: 12px; }
.rng input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 26px; background: none; cursor: pointer;
}
.rng input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px; background: var(--line-2);
}
.rng input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9.5px;
  border-radius: 50%; background: var(--surface); border: 1px solid var(--line-2);
  box-shadow: var(--shadow-m);
}
.rng input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--line-2); }
.rng input[type="range"]::-moz-range-thumb {
  width: 21px; height: 21px; border-radius: 50%; background: var(--surface);
  border: 1px solid var(--line-2); box-shadow: var(--shadow-m);
}
.rng__v {
  font-size: 12px; color: var(--ink-2); min-width: 5.5em; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 14px; font-weight: 600; letter-spacing: .04em;
  padding: 13px 22px; border-radius: var(--r-m); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: all var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--ink); color: var(--bg); }
.btn--primary:not(:disabled):hover { background: var(--accent); color: var(--accent-ink); }
.btn--primary:not(:disabled):active { transform: translateY(1px); }
.btn--ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink-2); }
.btn--ghost:not(:disabled):hover { border-color: var(--ink-4); color: var(--ink); }
.btn--quiet { background: none; color: var(--ink-3); padding: 8px 10px; font-weight: 500; font-size: 12.5px; }
.btn--quiet:hover { color: var(--ink); background: var(--bg-alt); }
.btn--danger { background: none; border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn--danger:hover { background: var(--danger-sub); }
.btn--block { width: 100%; }
.btn--sm { padding: 8px 14px; font-size: 12.5px; }

/* ── sticky action bar ──────────────────────────────── */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 12px max(18px, env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.bar__in { max-width: var(--maxw); margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bar__meta { font-size: 11.5px; color: var(--ink-4); line-height: 1.5; flex: 1; min-width: 0; }
.bar .btn { flex: none; min-width: 150px; }
@media (max-width: 420px) { .bar .btn { flex: 1; min-width: 0; } .bar__meta { display: none; } }

/* ── spinner ────────────────────────────────────────── */
.spin {
  width: 15px; height: 15px; flex: none; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── notes / alerts ─────────────────────────────────── */
.note {
  display: flex; gap: 10px; font-size: 12.5px; line-height: 1.8;
  padding: 12px 14px; border-radius: var(--r-m); border: 1px solid;
}
.note__k { flex: none; font-weight: 700; font-size: 11px; letter-spacing: .08em; padding-top: 2px; }
.note--info { background: var(--accent-sub); border-color: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--ink-2); }
.note--warn { background: var(--warn-sub); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--ink-2); }
.note--warn .note__k { color: var(--warn); }
.note--danger { background: var(--danger-sub); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--ink-2); }
.note--danger .note__k { color: var(--danger); }
.note--info .note__k { color: var(--accent); }

/* ── toast ──────────────────────────────────────────── */
.toasts {
  position: fixed; z-index: 90; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(420px, calc(100vw - 32px));
}
.toast {
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 500;
  padding: 11px 18px; border-radius: 100px; box-shadow: var(--shadow-l);
  animation: toastIn .3s var(--ease); max-width: 100%; text-align: center;
}
.toast--err { background: var(--danger); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.96); } }

/* ── empty ──────────────────────────────────────────── */
.empty { text-align: center; padding: 56px 20px; color: var(--ink-4); }
.empty__t { font-family: var(--serif); font-size: 16px; color: var(--ink-3); }
.empty__d { font-size: 12.5px; margin-top: 8px; line-height: 1.9; }

.spacer { height: 20px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 22px 0; }

/* 狭い画面ではセクション見出しの補足を次行へ送る */
@media (max-width: 559px) {
  .sec__hd { flex-wrap: wrap; }
  .sec__t { white-space: nowrap; }
  .sec__note { margin-left: 0; flex-basis: 100%; }
}

@media (max-width: 430px) { .brand__sub { display: none; } }
