:root {
  color-scheme: light;
  --bg: #eff0eb;
  --surface: #fffefa;
  --surface-strong: #ffffff;
  --ink: #111111;
  --muted: #626a5d;
  --line: #d9dfd0;
  --logo-green: #80a24d;
  --logo-green-light: #99cc66;
  --accent: #5f7a38;
  --accent-strong: #35471e;
  --accent-soft: #edf5e7;
  --tool-accent: #b24f37;
  --tool-accent-strong: #823a29;
  --tool-accent-soft: #fbece8;
  --warn: #b2452c;
  --warn-soft: #fff0ea;
  --shadow: 0 18px 45px rgba(35, 42, 32, 0.11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(128, 162, 77, 0.18), transparent 34%),
    linear-gradient(225deg, rgba(153, 204, 102, 0.13), transparent 30%),
    var(--bg);
  color: var(--ink);
}

button, input, select, summary, textarea { font: inherit; }

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 14px;
}

.top-bar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
  padding: 18px;
  background: rgba(255, 253, 248, 0.86);
  border: 1px solid var(--line);
  border-left: 5px solid var(--tool-accent);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-lockup { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo { width: 72px; height: 72px; flex: 0 0 auto; object-fit: contain; filter: drop-shadow(0 8px 14px rgba(35, 42, 32, 0.14)); }
.eyebrow { margin: 0 0 3px; color: var(--tool-accent-strong); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(1.65rem, 2.6vw, 2.45rem); line-height: 1.05; letter-spacing: 0; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tool-symbol { min-width: 44px; height: 32px; display: inline-flex; align-items: center; justify-content: center; padding: 0 8px; border: 1px solid var(--tool-accent); border-radius: 6px; background: var(--tool-accent-soft); color: var(--tool-accent-strong); font-family: "Cascadia Code", Consolas, monospace; font-size: 0.84rem; font-weight: 900; line-height: 1; white-space: nowrap; }

.action-bar { position: relative; z-index: 4; display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: 8px; width: 100%; }
.file-input, .hidden { display: none; }
.tools-menu { position: relative; }
.tools-menu summary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}
.tools-menu summary::-webkit-details-marker { display: none; }
.tools-menu summary::after { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.tools-menu[open] summary { border-color: rgba(128, 162, 77, 0.6); background: var(--accent-soft); }
.tools-menu-list { position: absolute; top: calc(100% + 6px); left: 0; z-index: 10; min-width: 190px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-strong); box-shadow: var(--shadow); }
.tools-menu-list a { display: block; padding: 11px 12px; color: var(--ink); font-size: 0.9rem; font-weight: 800; text-decoration: none; }
.tools-menu-list a + a { border-top: 1px solid var(--line); }
.tools-menu-list a:hover, .tools-menu-list a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }

.control-panel {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: auto minmax(330px, 1.2fr) minmax(300px, 1fr);
  gap: 12px 20px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.8);
  box-shadow: 0 10px 26px rgba(35, 42, 32, 0.08);
  backdrop-filter: blur(14px);
}

.control-group { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; margin: 0; padding: 0; border: 0; }
.control-group-title { color: var(--tool-accent-strong); font-size: 0.76rem; font-weight: 900; text-transform: uppercase; white-space: nowrap; }
.control-row { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.affix-group { grid-column: 1 / -1; }
.affix-group .control-row { width: 100%; flex-wrap: nowrap; }
.affix-group .text-input { width: auto; flex: 1 1 220px; }
.cleanup-group { grid-column: 1 / -1; }
.field-label { color: var(--muted); font-size: 0.82rem; font-weight: 700; white-space: nowrap; }

select, button, input[type="text"] { min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-strong); color: var(--ink); }
select { padding: 0 34px 0 11px; }
button { padding: 0 14px; cursor: pointer; font-weight: 800; transition: transform 120ms ease, border-color 120ms ease, background 120ms ease; }
button:hover, select:hover, input[type="text"]:hover, .tools-menu summary:hover { border-color: rgba(128, 162, 77, 0.6); }
button:active { transform: translateY(1px); }
.primary-button { border-color: var(--accent); background: var(--accent); color: white; }
.primary-button:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
.ghost-button { background: transparent; }
.text-input { width: min(150px, 100%); padding: 0 11px; }
.compact-input { width: 92px; padding: 0 10px; }
.small-select { min-height: 32px; padding-left: 9px; font-size: 0.8rem; }

.checkbox-control { min-height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-strong); cursor: pointer; font-size: 0.9rem; font-weight: 800; }
.checkbox-control:hover { border-color: rgba(128, 162, 77, 0.6); }
.checkbox-control input { width: 16px; height: 16px; accent-color: var(--accent); }

.status-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 38px; }
.status-pill, .stats { border: 1px solid var(--line); border-radius: 8px; background: rgba(255, 253, 248, 0.88); padding: 8px 12px; color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.status-valid { border-color: rgba(128, 162, 77, 0.34); background: var(--accent-soft); color: var(--accent-strong); }
.status-error { border-color: rgba(178, 69, 44, 0.3); background: var(--warn-soft); color: var(--warn); }

.editor-grid { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.editor-pane { min-height: 0; display: grid; grid-template-rows: auto 1fr; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.pane-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 50px; padding: 7px 14px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.6); }
.pane-header > label { font-weight: 900; }
.pane-header span { color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.pane-meta { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
textarea { width: 100%; height: 100%; min-height: 400px; resize: none; border: 0; outline: 0; padding: 18px; background: transparent; color: #142018; font-family: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 0.96rem; line-height: 1.55; tab-size: 2; }
textarea::placeholder { color: #8a948b; }
#formattedOutput { background: rgba(128, 162, 77, 0.045); }

.app-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 38px; padding: 0 4px; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.app-footer a { color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.app-footer span:has([data-version]) { display: inline-flex; align-items: center; gap: 12px; }
.app-footer [data-version] { color: var(--accent); }

@media (max-width: 1100px) {
  .control-panel { grid-template-columns: 1fr 1fr; }
  .cleanup-group { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .app-shell { width: min(100vw - 20px, 760px); min-height: calc(100vh - 20px); margin: 10px auto; }
  .control-panel, .editor-grid { grid-template-columns: 1fr; }
  .cleanup-group, .affix-group { grid-column: auto; }
  textarea { min-height: 300px; }
}

@media (max-width: 560px) {
  .top-bar { padding: 14px; }
  .brand-lockup { gap: 10px; }
  .brand-logo { width: 58px; height: 58px; }
  .action-bar { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .action-bar button, .tools-menu, .tools-menu summary { width: 100%; }
  .tools-menu-list { left: 0; right: auto; width: min(280px, calc(100vw - 50px)); }
  .control-group { grid-template-columns: 1fr; align-items: start; }
  .control-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); width: 100%; }
  .control-row select, .control-row input[type="text"], .checkbox-control { width: 100%; min-width: 0; }
  .affix-group .control-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .affix-group .text-input { width: 100%; }
  .cleanup-group .control-row { grid-template-columns: 1fr 1fr; }
  .pane-header { align-items: flex-start; flex-direction: column; }
  .pane-meta { justify-content: flex-start; width: 100%; }
  .status-row, .app-footer { align-items: stretch; flex-direction: column; }
  .app-footer { padding: 4px; }
  .app-footer > span:last-child { flex-wrap: wrap; }
}
