:root {
  color-scheme: dark;
  --bg: #0d1014;
  --panel: #14191f;
  --panel-raised: #191f27;
  --field: #090c10;
  --line: #29313a;
  --line-strong: #47515d;
  --text: #f3f0ea;
  --muted: #808b97;
  --muted-strong: #b1bac4;
  --amber: #f2bd68;
  --amber-soft: rgba(242, 189, 104, 0.12);
  --blue: #74b8ff;
  --blue-soft: rgba(116, 184, 255, 0.1);
  --green: #72dda1;
  --green-soft: rgba(114, 221, 161, 0.1);
  --red: #ff747d;
  --red-soft: rgba(255, 116, 125, 0.1);
  --shadow: rgba(0, 0, 0, 0.28);
}

body.light {
  color-scheme: light;
  --bg: #eceae5;
  --panel: #f9f7f2;
  --panel-raised: #fffdf9;
  --field: #f2efe8;
  --line: #d2cdc3;
  --line-strong: #9c968c;
  --text: #24231f;
  --muted: #7a766e;
  --muted-strong: #555149;
  --amber: #9a5c00;
  --amber-soft: rgba(154, 92, 0, 0.1);
  --blue: #1768a8;
  --blue-soft: rgba(23, 104, 168, 0.08);
  --green: #167345;
  --green-soft: rgba(22, 115, 69, 0.08);
  --red: #ba3942;
  --red-soft: rgba(186, 57, 66, 0.08);
  --shadow: rgba(62, 56, 46, 0.1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(242, 189, 104, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(242, 189, 104, 0.022) 1px, transparent 1px),
    radial-gradient(circle at 10% -12%, rgba(242, 189, 104, 0.1), transparent 30rem),
    var(--bg);
  background-size: 52px 52px, 52px 52px, auto, auto;
  color: var(--text);
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  transition: background-color 0.2s, color 0.2s;
}

button, input, textarea, select { font: inherit; }
button, select { color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.app { width: min(1220px, calc(100% - 48px)); margin: 0 auto; }
.sr-only { width: 1px; height: 1px; position: absolute; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

.topbar {
  height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 700; letter-spacing: 0.17em; }
.brand-mark { width: 31px; height: 31px; position: relative; display: block; border: 1px solid var(--line-strong); background: var(--panel); }
.brand-mark i, .brand-mark b { position: absolute; border-radius: 50%; }
.brand-mark i { inset: 6px; border: 1px solid var(--amber); }
.brand-mark b { width: 2px; height: 8px; top: 8px; left: 14px; border-radius: 0; background: var(--amber); transform-origin: 1px 7px; transform: rotate(42deg); }
.top-actions { display: flex; align-items: center; gap: 20px; }
.local-status { color: var(--muted); font: 500 10px "IBM Plex Mono", monospace; letter-spacing: 0.12em; }
.local-status i { width: 6px; height: 6px; display: inline-block; margin-right: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 9px var(--green); }
.square-button { width: 36px; height: 36px; border: 1px solid var(--line); background: transparent; font-size: 16px; }
.square-button:hover { border-color: var(--line-strong); background: var(--panel); }

.intro { min-height: 205px; display: flex; align-items: flex-end; justify-content: space-between; gap: 48px; padding: 46px 0 37px; }
.eyebrow { margin: 0; color: var(--muted); font: 500 9px "IBM Plex Mono", monospace; letter-spacing: 0.15em; }
.intro h1 { max-width: 760px; margin: 10px 0 0; font-size: clamp(38px, 5vw, 66px); font-weight: 500; line-height: 0.96; letter-spacing: -0.05em; }
.intro h1 em { color: var(--amber); font-family: Georgia, "Times New Roman", serif; font-weight: 400; }
.intro > p { width: min(360px, 36%); margin: 0 0 4px; color: var(--muted-strong); font-size: 13px; line-height: 1.7; }

.now-strip { min-height: 91px; display: grid; grid-template-columns: 145px 1fr 1.35fr 1.65fr 85px; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 20px 55px var(--shadow); }
.now-label { display: flex; align-items: center; gap: 12px; padding: 16px; border-right: 1px solid var(--line); }
.pulse { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 6px var(--green-soft); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px transparent; } }
.now-label small, .now-value small { display: block; color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.1em; }
.now-label strong { display: block; margin-top: 6px; color: var(--green); font: 600 9px "IBM Plex Mono", monospace; letter-spacing: 0.1em; }
.now-value { min-width: 0; padding: 16px 17px; border: 0; border-right: 1px solid var(--line); background: transparent; text-align: left; }
.now-value:hover { background: var(--amber-soft); }
.now-value strong { display: block; max-width: 100%; margin-top: 8px; overflow: hidden; color: var(--text); font: 500 clamp(13px, 1.4vw, 18px) "IBM Plex Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
.now-value.is-wide strong { font-size: clamp(11px, 1.12vw, 15px); }
.pause-button { border: 0; background: var(--amber); color: #241805; font: 700 8px "IBM Plex Mono", monospace; letter-spacing: 0.12em; }
.pause-button:hover { filter: brightness(1.07); }

.workbench { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 16px; margin-top: 16px; }
.input-card, .result-card, .batch-input-card, .batch-output-card { min-width: 0; border: 1px solid var(--line); background: var(--panel); }
.section-head { min-height: 73px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.section-head > div { display: flex; align-items: center; gap: 14px; }
.section-head > div > span { color: var(--amber); font: 600 11px "IBM Plex Mono", monospace; }
.section-head p { margin: 0 0 5px; color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.11em; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 500; }
.kind-badge, .validity { padding: 7px 9px; border: 1px solid var(--line); color: var(--muted); font: 600 8px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
.input-mode { display: grid; grid-template-columns: repeat(4, 1fr); padding: 10px; border-bottom: 1px solid var(--line); background: var(--panel-raised); }
.input-mode button { height: 34px; border: 0; border-right: 1px solid var(--line); background: var(--field); color: var(--muted); font: 600 8px "IBM Plex Mono", monospace; letter-spacing: 0.07em; }
.input-mode button:last-child { border-right: 0; }
.input-mode button:hover { color: var(--text); }
.input-mode button.is-active { background: var(--amber); color: #261903; }
#sourceInput { width: 100%; min-height: 196px; display: block; resize: vertical; padding: 24px; border: 0; border-bottom: 1px solid var(--line); outline: 0; background: var(--field); color: var(--text); font: 17px/1.7 "IBM Plex Mono", monospace; }
#sourceInput:focus { box-shadow: inset 3px 0 0 var(--amber); }
#sourceInput::placeholder, #batchInput::placeholder { color: var(--muted); }
.input-foot { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 10px 10px 10px 18px; }
.input-foot > span { color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; }
.input-foot > div { display: flex; align-items: center; gap: 4px; }
.input-foot button:not(.primary-button), .mini-head button { padding: 10px 8px; border: 0; background: transparent; color: var(--muted); font: 600 8px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
.input-foot button:not(.primary-button):hover, .mini-head button:hover { color: var(--text); }
.primary-button { min-width: 136px; height: 43px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 15px; border: 0; background: var(--amber); color: #241805; font: 700 9px "IBM Plex Mono", monospace; letter-spacing: 0.09em; }
.primary-button b { font-size: 18px; font-weight: 500; }
.primary-button:hover { filter: brightness(1.08); }

.validity { display: flex; align-items: center; gap: 7px; border: 0; }
.validity i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.validity.is-valid { color: var(--green); }
.validity.is-invalid { color: var(--red); }
.result-list { margin: 0; }
.result-list > div { min-height: 58px; display: grid; grid-template-columns: 145px minmax(0, 1fr) 50px; align-items: center; gap: 12px; padding: 9px 17px; border-bottom: 1px solid var(--line); }
.result-list dt { color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
.result-list dd { min-width: 0; margin: 0; overflow: hidden; color: var(--muted-strong); font: 500 11px "IBM Plex Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
.result-list button { padding: 7px 0; border: 0; background: transparent; color: var(--muted); font: 600 7px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
.result-list button:hover { color: var(--amber); }
.notice { min-height: 70px; display: flex; align-items: center; gap: 14px; margin: 13px; padding: 13px 15px; border: 1px solid var(--line); background: var(--green-soft); }
.notice > span { width: 28px; height: 28px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--green); color: var(--green); font-size: 12px; }
.notice strong { display: block; margin-bottom: 4px; font-size: 11px; font-weight: 600; }
.notice p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.45; }
.notice.is-error { background: var(--red-soft); }
.notice.is-error > span { border-color: var(--red); color: var(--red); }

.zone-section, .batch-section { margin-top: 76px; }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 40px; margin-bottom: 22px; }
.title-row h2 { margin: 9px 0 0; font-size: clamp(27px, 3.3vw, 42px); font-weight: 500; letter-spacing: -0.04em; }
.title-row > label { display: flex; flex-direction: column; gap: 8px; color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.1em; }
.title-row select { min-width: 205px; height: 42px; padding: 0 35px 0 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: 600 9px "IBM Plex Mono", monospace; letter-spacing: 0.05em; }
.zone-grid { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); background: var(--panel); box-shadow: 0 18px 50px var(--shadow); }
.zone-card { min-width: 0; min-height: 151px; padding: 18px; border-right: 1px solid var(--line); }
.zone-card:last-child { border-right: 0; }
.zone-card.is-reference { background: var(--amber-soft); box-shadow: inset 0 -2px 0 var(--amber); }
.zone-card small { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.07em; }
.zone-card small span:last-child { color: var(--amber); }
.zone-card strong { display: block; margin-top: 23px; font: 500 clamp(19px, 2vw, 27px) "IBM Plex Mono", monospace; letter-spacing: -0.04em; }
.zone-card p { margin: 9px 0 0; color: var(--muted-strong); font-size: 11px; }
.zone-card .zone-error { color: var(--red); font-size: 11px; }

.batch-title-row > p { width: min(410px, 42%); margin: 0; color: var(--muted-strong); font-size: 12px; line-height: 1.6; }
.batch-grid { display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 16px; }
.mini-head { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 0 16px; border-bottom: 1px solid var(--line); color: var(--muted); font: 600 8px "IBM Plex Mono", monospace; letter-spacing: 0.1em; }
.mini-head > div { display: flex; gap: 3px; }
.mini-head button:disabled { opacity: 0.35; cursor: default; }
#batchInput { width: 100%; min-height: 250px; display: block; resize: vertical; padding: 18px; border: 0; border-bottom: 1px solid var(--line); outline: 0; background: var(--field); color: var(--text); font: 12px/1.75 "IBM Plex Mono", monospace; }
#batchInput:focus { box-shadow: inset 3px 0 0 var(--amber); }
.batch-foot { min-height: 65px; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 10px 10px 10px 17px; }
.batch-foot > span { color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; }
.table-wrap { min-height: 250px; max-height: 250px; overflow: auto; background: var(--field); border-bottom: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { position: sticky; top: 0; z-index: 1; padding: 10px 9px; border-bottom: 1px solid var(--line); background: var(--panel-raised); color: var(--muted); font: 600 7px "IBM Plex Mono", monospace; letter-spacing: 0.08em; text-align: left; }
td { padding: 10px 9px; border-bottom: 1px solid var(--line); overflow: hidden; color: var(--muted-strong); font: 500 9px "IBM Plex Mono", monospace; text-overflow: ellipsis; white-space: nowrap; }
th:nth-child(1), td:nth-child(1) { width: 38px; }
th:nth-child(2), td:nth-child(2) { width: 31%; }
th:nth-child(4), td:nth-child(4) { width: 63px; }
td.is-ok { color: var(--green); }
td.is-error { color: var(--red); }
.empty-row td { height: 200px; color: var(--muted); text-align: center; }
.batch-summary { min-height: 65px; display: flex; align-items: center; justify-content: flex-end; gap: 22px; padding: 0 17px; color: var(--muted); font: 600 8px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
#batchValid { color: var(--green); }
#batchInvalid { color: var(--red); }

footer { min-height: 98px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 66px; border-top: 1px solid var(--line); color: var(--muted); font: 500 8px "IBM Plex Mono", monospace; letter-spacing: 0.08em; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; padding: 12px 16px; transform: translateY(12px); border: 1px solid var(--amber); background: var(--panel-raised); box-shadow: 0 12px 36px var(--shadow); color: var(--text); font: 600 9px "IBM Plex Mono", monospace; letter-spacing: 0.08em; opacity: 0; pointer-events: none; transition: 0.2s; }
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 1020px) {
  .now-strip { grid-template-columns: 135px 1fr 1.3fr 78px; }
  .now-value.is-wide { display: none; }
  .zone-grid { grid-template-columns: 1fr 1fr; }
  .zone-card:nth-child(2) { border-right: 0; }
  .zone-card:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 780px) {
  .app { width: min(100% - 28px, 1220px); }
  .intro { min-height: 0; display: block; padding: 38px 0 29px; }
  .intro > p { width: 100%; max-width: 510px; margin-top: 24px; }
  .now-strip { grid-template-columns: 1fr 1fr; }
  .now-label, .now-value { min-height: 82px; border-bottom: 1px solid var(--line); }
  .now-value:nth-of-type(2) { border-right: 0; }
  .now-value.is-wide { display: block; border-bottom: 0; }
  .pause-button { min-height: 70px; }
  .workbench, .batch-grid { grid-template-columns: 1fr; }
  .title-row { align-items: flex-start; flex-direction: column; gap: 22px; }
  .batch-title-row > p { width: 100%; }
  .zone-section, .batch-section { margin-top: 54px; }
}

@media (max-width: 540px) {
  .topbar { height: 70px; }
  .local-status { display: none; }
  .intro h1 { font-size: 42px; }
  .now-strip { display: block; }
  .now-label, .now-value, .now-value.is-wide { width: 100%; display: block; border-right: 0; border-bottom: 1px solid var(--line); }
  .pause-button { width: 100%; }
  .input-mode { grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); }
  .input-mode button { border: 0; }
  .input-foot { align-items: stretch; flex-direction: column; }
  .input-foot > div { display: grid; grid-template-columns: 1fr 1fr; }
  .input-foot .primary-button { grid-column: 1 / -1; width: 100%; }
  .result-list > div { grid-template-columns: 1fr 45px; }
  .result-list dt { grid-column: 1 / -1; }
  .result-list dd { font-size: 10px; }
  .zone-grid { display: block; }
  .zone-card { border-right: 0; border-bottom: 1px solid var(--line); }
  .zone-card:last-child { border-bottom: 0; }
  .title-row select { width: 100%; }
  footer { align-items: flex-start; flex-direction: column; justify-content: center; }
  footer span:nth-child(2) { display: none; }
}

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