/* Sumi ink on washi paper: near-black ink (never pure #000) on warm white, and the reverse in dark mode. */
:root {
  color-scheme: light;
  --bg: #f7f6f3;          /* washi */
  --surface: #fdfdfb;
  --surface-2: #efeeea;
  --ink: #1f1e1c;         /* sumi */
  --muted: #6b6964;
  --line: #e0ded8;
  --accent: #1f1e1c;
  --accent-ink: #f7f6f3;
  --accent-soft: #e9e8e3;
  --ok: #3d6b4f;
  --ok-soft: #e3ece5;
  --err: #a33b2f;         /* shu, the seal red */
  --err-soft: #f4e2de;
  --shadow: 0 1px 2px rgba(20,18,16,.04), 0 6px 20px rgba(20,18,16,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161514; --surface: #1e1d1b; --surface-2: #272624; --ink: #ebe9e4;
    --muted: #9c9993; --line: #34322f; --accent: #ebe9e4;
    --accent-ink: #161514; --accent-soft: #2d2c29; --ok: #8fbf9c; --ok-soft: #1e2b22;
    --err: #e58b7f; --err-soft: #34201d; --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161514; --surface: #1e1d1b; --surface-2: #272624; --ink: #ebe9e4;
  --muted: #9c9993; --line: #34322f; --accent: #ebe9e4;
  --accent-ink: #161514; --accent-soft: #2d2c29; --ok: #8fbf9c; --ok-soft: #1e2b22;
  --err: #e58b7f; --err-soft: #34201d; --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
}
.wrap { max-width: 760px; margin: 0 auto; padding: 48px 16px 64px; }

header.hero { text-align: center; margin-bottom: 32px; }
.kicker {
  font-family: "Noto Serif Thai", serif;
  font-size: 15px; letter-spacing: .5em; color: var(--muted);
  margin-bottom: 8px;
}
h1 {
  font-family: "Noto Serif Thai", serif;
  font-weight: 700; font-size: clamp(28px, 6vw, 40px);
  margin: 0 0 8px; line-height: 1.3;
}
.sub { color: var(--muted); margin: 0; }
.demo {
  display: inline-flex; align-items: center; gap: 12px;
  margin-top: 18px; padding: 8px 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 15px;
}
.demo .from { color: var(--muted); }
.demo .to { font-weight: 600; color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 24px; margin-bottom: 20px;
}
.step-title { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 0 0 14px; font-size: 17px; }
.step-num {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 15px; font-weight: 700;
  font-family: "Noto Serif Thai", serif;
}

/* Direction toggle */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; background: var(--surface-2); border-radius: 12px; margin-bottom: 16px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  text-align: center; padding: 10px 8px; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-weight: 500; transition: background .15s, color .15s;
}
.seg input:checked + label { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 1px 3px rgba(0,0,0,.08); font-weight: 600; }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Drop zone */
.drop {
  display: block; border: 2px dashed var(--line); border-radius: 14px;
  padding: 36px 16px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface-2);
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.drop svg { width: 44px; height: 44px; color: var(--accent); margin-bottom: 8px; }
.drop strong { display: block; font-size: 18px; margin-bottom: 4px; }
.drop span { color: var(--muted); font-size: 14px; }
.drop input { display: none; }

/* Options */
details.opts { margin-top: 16px; }
details.opts summary {
  cursor: pointer; color: var(--muted); font-size: 15px; list-style: none;
  display: inline-flex; align-items: center; gap: 6px; user-select: none;
}
details.opts summary::-webkit-details-marker { display: none; }
details.opts summary::before { content: "▸"; transition: transform .15s; display: inline-block; }
details.opts[open] summary::before { transform: rotate(90deg); }
.opt-list { display: grid; gap: 4px; margin-top: 12px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px;
  border-radius: 10px; cursor: pointer;
}
.opt:hover { background: var(--surface-2); }
.opt input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.opt b { font-weight: 500; display: block; }
.opt small { color: var(--muted); font-size: 13.5px; }

/* File results */
.files { display: grid; gap: 12px; }
.file {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.file .icon {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12px;
}
.file.done .icon { background: var(--ok-soft); color: var(--ok); }
.file.error .icon { background: var(--err-soft); color: var(--err); }
.file .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .meta { color: var(--muted); font-size: 14px; }
.file.error .meta { color: var(--err); }
.file .info { min-width: 0; }
.preview {
  grid-column: 1 / -1; font-size: 14px; background: var(--surface-2); border-radius: 8px;
  padding: 10px 12px; display: grid; gap: 4px;
}
.preview div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview .lbl { color: var(--muted); display: inline-block; min-width: 56px; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; cursor: pointer;
  padding: 10px 18px; background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  transition: filter .15s, transform .05s;
}
.btn:hover { opacity: .86; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

.spinner {
  width: 20px; height: 20px; border: 2.5px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.privacy svg { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; }
.hidden { display: none !important; }

@media (max-width: 520px) {
  .wrap { padding-top: 32px; }
  .card { padding: 18px; }
  .file { grid-template-columns: auto 1fr; }
  .file .btn { grid-column: 1 / -1; justify-content: center; }
}


.file.none .icon { background: var(--surface-2); color: var(--muted); }
.preview .lbl { margin-right: 8px; }


/* Wider layout for the tool hub */
.wrap.wide { max-width: 920px; }

/* Back link on tool pages */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.topbar.end { justify-content: flex-end; }

/* Theme switch: system / light / dark */
.theme-switch {
  display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
}
.theme-switch button {
  display: grid; place-items: center; width: 32px; height: 28px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.theme-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-switch svg { width: 16px; height: 16px; }
.back {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  text-decoration: none; font-size: 15px; transition: color .15s, border-color .15s;
}
.back:hover { color: var(--ink); border-color: var(--accent); }
.back:focus-visible, .tool-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Tool hub */
.hub-group > h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 28px 4px 12px; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tool-card {
  display: flex; gap: 14px; align-items: flex-start; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  color: inherit; text-decoration: none; transition: border-color .15s, transform .15s;
}
.tool-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.tool-card b { display: block; font-weight: 600; margin-bottom: 2px; }
.tool-card small { display: block; color: var(--muted); font-size: 14px; line-height: 1.5; }
.tool-icon {
  flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-family: "Noto Serif Thai", serif; font-weight: 700; font-size: 17px; white-space: nowrap;
}

/* Footer */
footer.site { text-align: center; color: var(--muted); font-size: 14px; margin-top: 32px; display: grid; gap: 6px; }
footer.site a { color: inherit; }
footer.site .author { color: var(--ink); font-weight: 500; }
footer.site .small { font-size: 13px; }
.others { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 12px; }
.others a {
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13.5px; text-decoration: none; transition: color .15s, border-color .15s;
}
.others a:hover { color: var(--ink); border-color: var(--accent); }

/* Form fields */
.field {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; max-width: 100%;
}
.field:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.field-row label { font-weight: 500; }
textarea.field { width: 100%; min-height: 140px; resize: vertical; line-height: 1.6; }
.hint { color: var(--muted); font-size: 14px; margin: 10px 2px 0; }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg label b { display: block; font-weight: 600; }
.seg label small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }
@media (max-width: 420px) { .seg label small { display: none; } }
