/* ----- Dark ----- */
html[data-theme="dark"] {
  --bg: #0d1117;
  --card: #161b22;
  --border: #30363d;
  --text: #cdd6dd;
  --muted: #6b7c8c;
  --en: #89ddff;
  --de: #c792ea;
  --good: #a6e3a1;
  --warn: #ebcb8b;
  --bad: #e89393;
  --accent: #82aaff;
  --de-em-opacity: 0.95;
  --btn-alt-bg: transparent;
  --btn-alt-hover: rgba(255, 255, 255, 0.06);
  --primary-green: #238636;
  --primary-green-hover: #2ea043;
  --primary-border: #2ea043;
  --kbd-bg: #21262d;
  --kbd-border: var(--border);
  --dict-slot-bg: #080b10;
}

/* ----- Light ----- */
html[data-theme="light"] {
  --bg: #f6f8fa;
  --card: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --en: #0969da;
  --de: #8250df;
  --good: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;
  --accent: #0969da;
  --de-em-opacity: 1;
  --btn-alt-bg: #f6f8fa;
  --btn-alt-hover: #eaeef2;
  --primary-green: #1a7f37;
  --primary-green-hover: #116329;
  --primary-border: #116329;
  --kbd-bg: #eff2f5;
  --kbd-border: #d0d7de;
  --dict-slot-bg: #e8ecf3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    ui-sans-serif,
    system-ui,
    "Segoe UI",
    Roboto,
    sans-serif;
  line-height: 1.5;
}

.layout {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.25rem;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 1.35rem;
  color: var(--accent);
}

.top-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: flex-end;
  justify-content: flex-end;
}

.tag {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.theme-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}

.theme-box label {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

#selTheme,
#selSplit {
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.card {
  margin-top: 1rem;
  padding: 1.1rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.hidden {
  display: none !important;
}

label {
  display: block;
  margin-top: 0.65rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.hint {
  font-weight: 400;
  opacity: 0.85;
}

input,
textarea {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

textarea {
  min-height: 4.5rem;
  resize: vertical;
}

textarea:focus {
  outline: 2px solid var(--de);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  margin-top: 0.75rem;
  padding: 0.45rem 0.95rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--btn-alt-bg);
  color: var(--en);
}

button:hover:not(:disabled) {
  background: var(--btn-alt-hover);
}

button.primary {
  background: var(--primary-green);
  border-color: var(--primary-border);
  color: #fff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--primary-green-hover);
}

#hintKeys kbd,
.fine kbd {
  font-family:
    ui-monospace,
    "Cascadia Code",
    monospace;
  font-size: 0.75rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--kbd-border);
  background: var(--kbd-bg);
  color: var(--text);
}

.progress {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.85rem 0;
}

.lbl {
  margin: 0.75rem 0 0.2rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lbl.en {
  color: var(--en);
}

.lbl.de {
  color: var(--de);
}

.para {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.de-em {
  opacity: var(--de-em-opacity);
}

.fine {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.fine strong {
  color: var(--text);
}

#hintKeys strong {
  color: inherit;
}

#out {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border);
}

.verdict.good .tone {
  color: var(--good);
}

.verdict.warn .tone {
  color: var(--warn);
}

.verdict.bad .tone {
  color: var(--bad);
}

.verdict .sub {
  color: var(--muted);
  font-size: 0.85rem;
}

.btns {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lead {
  margin: 0 0 0.75rem;
  color: var(--accent);
  font-size: 1rem;
}

/* ----- Two-pane shell + dict.cc iframe ----- */

.shell {
  display: grid;
  align-items: stretch;
  min-height: 100vh;
}

/* Dual column ratios: drill (left) · dict (right). Min widths keep narrow panes usable. */
.shell[data-split="50-50"] {
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
}

.shell[data-split="70-30"] {
  grid-template-columns: minmax(260px, 7fr) minmax(180px, 3fr);
}

.shell[data-split="60-40"] {
  grid-template-columns: minmax(260px, 6fr) minmax(200px, 4fr);
}

.shell[data-split="40-60"] {
  grid-template-columns: minmax(220px, 4fr) minmax(240px, 6fr);
}

.shell[data-split="30-70"] {
  grid-template-columns: minmax(180px, 3fr) minmax(260px, 7fr);
}

/* Fallback when attribute missing (should not happen on dual page) */
.shell:not([data-split]) {
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
}

.drill-pane {
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.drill-pane .layout {
  max-width: 48rem;
  margin: 0 auto;
  padding-bottom: 2rem;
}

.dict-pane-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100vh;
  background: var(--bg);
  --dict-iframe-min: calc(100vh - 2.75rem);
  --dict-iframe-min: calc(100dvh - 2.75rem);
}

.dict-head {
  flex: 0 0 auto;
  padding: 0.85rem 1rem 0.95rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.dict-head.dict-head-min {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  flex-wrap: nowrap;
}

.dict-zoom-tog {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin: 0;
  white-space: nowrap;
  font-size: 0.68rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.dict-zoom-tog input {
  margin: 0;
  width: auto;
  accent-color: var(--primary-green);
}

.dict-head-min input[type="search"] {
  flex: 1 1 auto;
  margin: 0;
  min-width: 0;
  padding: 0.35rem 0.45rem;
  font-size: 0.875rem;
}

button.btn-icon {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.28rem 0.42rem;
  font-size: 0.82rem;
  line-height: 1.1;
}

button.tight {
  margin-top: 0;
  padding: 0.45rem 0.72rem;
  font-size: 0.87rem;
}

.dict-frame-slot {
  flex: 1 1 auto;
  position: relative;
  min-height: 280px;
  background: var(--dict-slot-bg);
  overflow: auto;
}

.dict-zoom-inner {
  width: 100%;
  min-height: 100%;
}

/* Viewport-based min height (minus slim dict toolbar); dict.cc scrolls inside the iframe */
.dict-zoom-inner iframe {
  display: block;
  border: none;
  width: 100%;
  min-height: var(--dict-iframe-min);
  background: var(--dict-slot-bg);
}

.dict-frame-slot.is-compact .dict-zoom-inner {
  width: calc(100% / 0.9);
  min-height: calc(var(--dict-iframe-min) / 0.9);
  transform: scale(0.9);
  transform-origin: top left;
  /* scaled content lives in a taller layout box so the visual bottom isn't clipped */
  padding-bottom: clamp(52px, 14dvh, 220px);
}

@supports (zoom: 0.9) {
  .dict-frame-slot.is-compact .dict-zoom-inner {
    width: 100%;
    min-height: 100%;
    transform: none;
    padding-bottom: 0;
  }

  .dict-frame-slot.is-compact .dict-zoom-inner iframe {
    zoom: 0.9;
    width: 100%;
    min-height: var(--dict-iframe-min);
  }
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .drill-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .dict-pane-inner {
    min-height: unset;
  }
}