:root {
  color-scheme: light;
  --paper: #f7f4ef;
  --ink: #202326;
  --muted: #697176;
  --line: #d9d4cc;
  --panel: #ffffff;
  --green: #2f766d;
  --blue: #345f9f;
  --red: #a3484c;
  --gold: #b17626;
  --shadow: 0 18px 50px rgba(32, 35, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(47, 118, 109, 0.08), transparent 28%),
    linear-gradient(180deg, #fbfaf7, var(--paper));
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Hiragino Sans", "Yu Gothic", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 38px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: #b7ada2;
  background: #fcfaf7;
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 28px 22px;
  background: rgba(255, 255, 255, 0.72);
}

.brand-block {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.65rem;
}

h2 {
  font-size: 1rem;
}

.panel {
  border-top: 1px solid var(--line);
  padding: 20px 0;
}

.panel.compact {
  color: var(--muted);
  font-size: 0.92rem;
}

.panel-heading,
.toolbar,
.reader-topline,
.inline-control,
.status-row {
  display: flex;
  align-items: center;
}

.panel-heading,
.reader-topline {
  justify-content: space-between;
  gap: 12px;
}

.small-button {
  min-height: 31px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.language-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 14px;
}

.language-toggle {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fff;
  cursor: pointer;
}

.language-toggle input {
  inline-size: 20px;
  block-size: 20px;
  accent-color: var(--green);
}

.language-code {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.language-name {
  font-weight: 700;
}

.language-script {
  color: var(--muted);
  font-size: 0.8rem;
}

.file-drop {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px dashed #aeb7b1;
  border-radius: 8px;
  margin-top: 14px;
  padding: 14px;
  background: #fdfdfb;
  cursor: pointer;
}

.file-drop input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.file-drop small,
.note {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.file-icon {
  display: grid;
  place-items: center;
  inline-size: 38px;
  block-size: 38px;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
  font-size: 1.3rem;
  font-weight: 700;
}

.url-form {
  margin-top: 18px;
}

.url-form label {
  display: block;
  margin-bottom: 7px;
  font-weight: 700;
}

.inline-control {
  gap: 8px;
}

.inline-control input {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 38px;
  padding: 0 11px;
}

.note {
  margin: 8px 0 0;
}

.legend-row {
  display: flex;
  gap: 9px;
  align-items: center;
  margin-top: 10px;
}

.swatch {
  inline-size: 18px;
  block-size: 18px;
  border-radius: 4px;
}

.swatch.phrase {
  background: rgba(177, 118, 38, 0.24);
  border: 1px solid rgba(177, 118, 38, 0.7);
}

.swatch.word {
  background: rgba(52, 95, 159, 0.16);
  border: 1px solid rgba(52, 95, 159, 0.45);
}

.swatch.unknown {
  background: rgba(163, 72, 76, 0.12);
  border: 1px solid rgba(163, 72, 76, 0.36);
}

.workspace {
  min-width: 0;
  padding: 30px clamp(18px, 4vw, 54px);
}

.toolbar {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.toolbar h2 {
  font-size: clamp(1.2rem, 2.2vw, 2rem);
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#analyzeButton {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.editor-wrap {
  display: block;
}

textarea {
  width: 100%;
  min-height: 170px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--ink);
  background: #fffefc;
  box-shadow: var(--shadow);
  line-height: 1.65;
}

.status-row {
  flex-wrap: wrap;
  gap: 12px;
  margin: 18px 0;
}

.status-row div,
.status-row p {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.76);
}

.status-row strong {
  margin-right: 6px;
  color: var(--blue);
}

.status-row span,
.status-row p {
  color: var(--muted);
}

.status-row p.is-error {
  border-color: rgba(163, 72, 76, 0.45);
  color: var(--red);
}

.reader-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.density-control {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.density-control button {
  border: 0;
  border-radius: 0;
  min-height: 32px;
}

.density-control button.is-active {
  color: #fff;
  background: var(--blue);
}

.annotated-text {
  margin-top: 18px;
  min-height: 210px;
  line-height: 1.6;
}

.annotation-unit {
  display: inline-flex;
  flex-direction: column;
  vertical-align: top;
  max-width: min(280px, 100%);
  margin: 0 5px 16px 0;
  border-radius: 7px;
  padding: 4px 6px 6px;
  break-inside: avoid;
}

.source-token {
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.annotation-unit.is-phrase {
  border: 1px solid rgba(177, 118, 38, 0.42);
  background: rgba(177, 118, 38, 0.15);
}

.annotation-unit.is-word {
  border: 1px solid rgba(52, 95, 159, 0.28);
  background: rgba(52, 95, 159, 0.1);
}

.annotation-unit.is-unknown {
  border: 1px solid rgba(163, 72, 76, 0.28);
  background: rgba(163, 72, 76, 0.08);
}

.translation-stack {
  display: grid;
  gap: 3px;
  margin-top: 5px;
  color: #343a3f;
  font-size: 0.78rem;
  line-height: 1.25;
}

.translation-line {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 5px;
}

.translation-line b {
  color: var(--green);
  font-size: 0.72rem;
}

.translation-line span {
  overflow-wrap: anywhere;
}

.pronunciation {
  color: var(--muted);
}

.punctuation {
  display: inline;
  margin-right: 5px;
  font-size: 1.08rem;
}

.annotated-text.is-compact .annotation-unit {
  margin-bottom: 9px;
}

.annotated-text.is-compact .translation-stack {
  font-size: 0.7rem;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .language-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .workspace,
  .sidebar {
    padding-inline: 14px;
  }

  .language-grid {
    grid-template-columns: 1fr;
  }

  .status-row div,
  .status-row p {
    width: 100%;
  }

  .reader-topline {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* --- Added styles for DeepL settings & Export dropdown --- */
.actions-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.export-control {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  min-width: 180px;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.dropdown-menu.hidden {
  display: none;
}

.dropdown-menu button {
  border: 0;
  border-radius: 0;
  padding: 10px 14px;
  text-align: left;
  background: transparent;
  min-height: auto;
  font-size: 0.88rem;
  width: 100%;
}

.dropdown-menu button:hover {
  background: #f5f3ef;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.field-row label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.field-row input,
.field-row select {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.9rem;
  background: #fff;
}

.toggle-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.toggle-control input {
  inline-size: 18px;
  block-size: 18px;
  accent-color: var(--green);
}

.cache-info {
  margin-top: 14px;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
  font-size: 0.88rem;
}

.cache-info p {
  margin: 0 0 8px;
}

.cache-info strong {
  color: var(--blue);
}

.button-row {
  display: flex;
  gap: 8px;
}

.button-row button.danger {
  border-color: rgba(163, 72, 76, 0.4);
  color: var(--red);
}

.button-row button.danger:hover {
  background: rgba(163, 72, 76, 0.05);
}

/* Export styling helper */
.annotated-text.is-exporting {
  background: #fff !important;
  padding: 24px !important;
  border-radius: 8px !important;
  border: 1px solid var(--line) !important;
  max-width: 800px !important;
  margin: 0 auto !important;
}

