:root {
  color-scheme: light;
  --ink: #1d261f;
  --muted: #657166;
  --paper: #f8f5ed;
  --panel: #fffdfa;
  --line: #ded7c8;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d7eee9;
  --warning: #b45309;
  --shadow: 0 18px 50px rgba(55, 50, 39, 0.14);
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(15, 118, 110, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "Noto Serif TC", "PingFang TC", serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button,
textarea {
  font: inherit;
}

input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.mobile-tabs {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(420px, 1.15fr);
  gap: 18px;
  height: 100vh;
  min-height: 620px;
  padding: 18px;
}

.pane {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 250, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 84px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.8), rgba(248, 245, 237, 0.62));
}

.kicker {
  margin: 0 0 5px;
  color: var(--accent);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

#sourceText {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  padding: 22px;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-family: "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
  line-height: 1.75;
  -webkit-overflow-scrolling: touch;
}

#sourceText::placeholder {
  color: #9a927f;
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: #fbf8f0;
}

.action-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.language-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 122px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
}

.language-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.language-toggle label {
  display: grid;
  min-height: 40px;
  place-items: center;
  padding: 0 10px;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.language-toggle input:checked + label {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.language-toggle label + input + label {
  border-left: 1px solid var(--line);
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: 0.88rem;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--accent-strong);
  cursor: pointer;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-weight: 800;
  white-space: nowrap;
}

#epubInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-weight: 700;
  white-space: nowrap;
  transition: transform 150ms ease, background 150ms ease;
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--accent-strong);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.64;
}

.button-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.status-row {
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--line);
  background: #fffdfa;
}

.progress-shell {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8e1d5;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

#statusText {
  margin: 9px 0 0;
  color: var(--muted);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: 0.88rem;
}

.result {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  display: grid;
  min-height: 100%;
  align-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  max-width: 34rem;
  margin: 0;
  line-height: 1.7;
}

.sentence-card {
  border-bottom: 1px solid var(--line);
  padding: 20px 2px 22px;
}

.sentence-card:first-child {
  padding-top: 2px;
}

.sentence-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: var(--muted);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.sentence-state[data-kind="error"] {
  color: var(--warning);
}

.chapter-title {
  margin: 0 0 10px;
  color: var(--warning);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chapter-title:empty {
  display: none;
}

.sentence-translation {
  margin: 0 0 14px;
  color: #123e3b;
  font-family: "Noto Serif TC", "Songti TC", Georgia, serif;
  font-size: clamp(1.2rem, 1.7vw, 1.55rem);
  font-weight: 700;
  line-height: 1.65;
}

.phrase-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 8px;
}

.phrase {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.1rem;
  max-width: 100%;
  padding: 5px 8px 6px;
  border: 1px solid #e5dece;
  border-radius: 8px;
  background: #fffefa;
}

.phrase-zh {
  max-width: 16rem;
  color: #0f766e;
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
}

.phrase-en {
  max-width: 16rem;
  margin-top: 4px;
  color: var(--ink);
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 0.93rem;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    background-size: 28px 28px;
  }

  .mobile-tabs {
    position: fixed;
    z-index: 20;
    top: 0;
    right: 0;
    left: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 8px calc(10px + var(--safe-left));
    border-bottom: 1px solid var(--line);
    background: rgba(248, 245, 237, 0.94);
    backdrop-filter: blur(16px);
  }

  .mobile-tab {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffefa;
    color: var(--muted);
    font-family: "Avenir Next", "Trebuchet MS", sans-serif;
    font-weight: 800;
  }

  .mobile-tab.is-active {
    border-color: var(--accent-strong);
    background: var(--accent);
    color: white;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: 100dvh;
    min-height: 0;
    padding: calc(58px + var(--safe-top)) calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left));
  }

  .pane {
    display: none;
    min-height: 0;
    border-radius: 8px;
  }

  body[data-mobile-view="input"] .input-pane,
  body[data-mobile-view="output"] .output-pane {
    display: flex;
  }

  .pane-header {
    min-height: 68px;
    padding: 14px 15px 12px;
  }

  h1,
  h2 {
    font-size: 1.25rem;
  }

  .toolbar {
    gap: 6px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  #sourceText {
    min-height: 0;
    padding: 16px;
    font-size: 16px;
    line-height: 1.65;
  }

  .input-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .action-cluster {
    align-items: stretch;
    flex-direction: column;
  }

  .language-toggle {
    width: 100%;
  }

  .file-button {
    width: 100%;
  }

  .primary-button {
    width: 100%;
  }

  .status-row {
    padding: 12px 15px 10px;
  }

  .result {
    padding: 14px;
  }

  .sentence-card {
    padding: 16px 0 18px;
  }

  .sentence-translation {
    font-size: 1.12rem;
  }

  .phrase-grid {
    gap: 8px 6px;
  }

  .phrase {
    min-width: 2.8rem;
    padding: 5px 7px 6px;
  }

  .phrase-zh,
  .phrase-en {
    max-width: 11rem;
  }
}
