:root {
  color-scheme: light dark;
  --bg: #f2f4f7;
  --panel: #ffffff;
  --panel-alt: #f8f9fb;
  --border: #d7dce3;
  --text: #1c1f24;
  --muted: #5c6773;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --handle: #b9c2cf;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --pane-header-height: 48px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --button-height: 34px;
  --button-font-size: .85rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --panel: #171b21;
    --panel-alt: #1c2128;
    --border: #2b323b;
    --text: #e6e9ee;
    --muted: #9aa5b1;
    --accent: #5b8cff;
    --accent-text: #0b1020;
    --handle: #3a434e;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
}

/* ---- header ---- */

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 2;
}

.app-title {
  margin: 0;
  font-size: clamp(0.95rem, 1.55vw + 0.62rem, 1.25rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: .01em;
}

.app-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.control-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--button-height);
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font: inherit;
  font-size: var(--button-font-size);
  line-height: 1;
  padding: 0 12px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease;
}

.control-button:hover { border-color: var(--accent); }
.control-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- workspace / splitter ---- */

.workspace {
  --split: 50%;
  flex: 1 1 auto;
  display: flex;
  min-width: 0;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  overflow: hidden;
}

.pane-input { flex: 0 0 var(--split); }
.pane-output { flex: 1 1 0; background: var(--panel-alt); }

.pane-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--pane-header-height);
  padding: 4px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.pane-output .pane-header { background: var(--panel-alt); }

.pane-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

.pane-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.pane-button {
  font-weight: 500;
}

.pane-button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.pane-button:disabled:hover { border-color: var(--border); }

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

.solve-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--button-height);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: var(--button-font-size);
  font-weight: 600;
  line-height: 1;
  padding: 0 18px;
  border-radius: 8px;
  cursor: pointer;
}

.solve-button:hover { filter: brightness(1.06); }
.solve-button:disabled { opacity: .6; cursor: progress; }
.solve-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.editor {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  margin: 0;
  border: 0;
  outline: none;
  resize: none;
  padding: 14px 16px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .92rem;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
}

.editor::placeholder { color: var(--muted); opacity: .8; }

.splitter {
  flex: 0 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  cursor: col-resize;
  touch-action: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.splitter-handle {
  width: 3px;
  height: 44px;
  border-radius: 2px;
  background: var(--handle);
  transition: background .15s ease;
}

.splitter:hover .splitter-handle,
body.is-resizing .splitter-handle { background: var(--accent); }

.splitter:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

body.is-resizing { user-select: none; cursor: col-resize; }

/* ---- about dialog ---- */

.about-dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  max-width: min(92vw, 460px);
}

.about-dialog::backdrop { background: rgba(0, 0, 0, .45); }

.about-body {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.about-app { margin: 0; font-weight: 600; font-size: 1.05rem; }
.about-author { margin: 0; color: var(--muted); font-size: .95rem; }
.about-credit {
  margin: 0;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.about-credit a { color: var(--accent); }
.about-body form { margin: 0; display: flex; justify-content: flex-end; }

/* ---- phone: stack the panes ---- */

@media (max-width: 599px) {
  .app-header { flex-wrap: wrap; }

  .pane-output .pane-header {
    flex-wrap: wrap;
    padding-block: 6px;
  }

  .pane-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 4px;
  }

  .workspace { flex-direction: column; }

  .pane-input { flex: 0 0 var(--split); }

  .splitter {
    flex: 0 0 10px;
    cursor: row-resize;
    border-left: 0;
    border-right: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .splitter-handle { width: 44px; height: 3px; }

  body.is-resizing { cursor: row-resize; }
}
