:root {
  color-scheme: light;
  --ink: #3f4146;
  --muted: #767a82;
  --line: #d9dde3;
  --paper: #fffdf8;
  --surface: #f3f1ec;
  --accent: #b98145;
  --accent-dark: #6d4725;
  --focus: #2c6f82;
  --page-scale: 1;
  --dock-height: min(34svh, 310px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--surface);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
}

body.has-image-dock {
  padding-bottom: var(--dock-height);
}

button,
[contenteditable] {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(220px, 18vw) 1fr;
  min-height: 100svh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 32px 24px;
  border-right: 1px solid var(--line);
  background: #ece8df;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 0.95;
}

.page-tabs {
  display: grid;
  gap: 8px;
}

.tab,
.text-button,
.control-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
}

.tab {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 10px 12px;
  text-align: left;
  font-weight: 800;
}

.tab span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.tab.is-active {
  border-color: rgba(109, 71, 37, 0.26);
  background: rgba(255, 253, 248, 0.76);
  color: var(--accent-dark);
}

.controls {
  display: grid;
  grid-template-columns: 46px 46px 1fr;
  gap: 8px;
  margin-top: auto;
}

.reader-tools {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(63, 65, 70, 0.14);
  background: rgba(255, 253, 248, 0.58);
}

.size-control,
.toggle-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.size-control output {
  color: var(--accent-dark);
}

#pageSize {
  width: 100%;
  accent-color: var(--accent-dark);
}

.toggle-control input {
  width: 46px;
  height: 26px;
  accent-color: var(--accent-dark);
}

.control-button,
.text-button {
  min-height: 44px;
  border-color: rgba(63, 65, 70, 0.18);
  background: rgba(255, 253, 248, 0.68);
  font-weight: 800;
}

.text-button {
  padding: 0 14px;
  color: var(--accent-dark);
}

.status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.reader {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.reader-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 30px 44px 18px;
  border-bottom: 1px solid var(--line);
}

.reader-header h2 {
  color: var(--ink);
  font-size: clamp(2.1rem, 4vw, 4rem);
  line-height: 0.95;
}

.reader-header p:last-child {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.script-page {
  overflow: auto;
  min-height: 0;
  padding: 38px 44px 72px;
  background:
    linear-gradient(90deg, rgba(185, 129, 69, 0.12) 0 3px, transparent 3px),
    var(--paper);
  -webkit-overflow-scrolling: touch;
}

.script-section {
  max-width: 1480px;
  margin: 0 0 40px;
  padding-left: 22px;
}

.script-section:last-child {
  margin-bottom: 0;
}

.line-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  column-gap: 10px;
  margin: 0 0 8px;
}

.line-number {
  color: var(--ink);
  font-size: clamp(1.2rem, 1.45vw, 1.72rem);
  font-weight: 600;
  line-height: 1.28;
  text-align: right;
}

.line-copy {
  min-width: 0;
}

.english,
.note {
  outline: none;
  border-radius: 3px;
  transition:
    background 160ms ease,
    box-shadow 160ms ease;
}

.english {
  color: var(--ink);
  font-size: calc(clamp(1.2rem, 1.45vw, 1.72rem) * var(--page-scale));
  font-weight: 600;
  line-height: 1.28;
}

.note {
  margin-top: 2px;
  color: var(--ink);
  font-size: calc(clamp(1rem, 1.18vw, 1.38rem) * var(--page-scale));
  font-weight: 700;
  line-height: 1.28;
}

.line-number {
  font-size: calc(clamp(1.2rem, 1.45vw, 1.72rem) * var(--page-scale));
}

.image-dock {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: none;
  height: var(--dock-height);
  margin: 0;
  padding: 10px;
  border-top: 1px solid rgba(63, 65, 70, 0.24);
  background: rgba(15, 17, 20, 0.9);
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.18);
}

body.has-image-dock .image-dock {
  display: block;
}

.image-dock img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.english:focus,
.note:focus {
  background: #fff5de;
  box-shadow: 0 0 0 3px rgba(44, 111, 130, 0.18);
}

.script-page.is-swapping {
  animation: pageIn 240ms ease both;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 16px;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  h1 {
    font-size: clamp(1.55rem, 5vw, 2.2rem);
  }

  .page-tabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .tab {
    justify-content: center;
    min-height: 42px;
    padding: 8px;
  }

  .tab span {
    display: none;
  }

  .controls {
    margin-top: 0;
  }

  .reader-tools {
    padding: 12px;
  }

  .reader-header {
    padding: 20px 20px 14px;
  }

  .script-page {
    padding: 26px 18px 54px;
  }

  .script-section {
    margin-bottom: 34px;
    padding-left: 0;
  }

  .line-item {
    grid-template-columns: 28px minmax(0, 1fr);
    column-gap: 8px;
  }
}

@media (max-width: 560px) {
  .sidebar {
    gap: 12px;
    padding: 14px 12px;
  }

  .sidebar .eyebrow {
    display: none;
  }

  .page-tabs {
    gap: 6px;
  }

  .tab {
    min-height: 44px;
    font-size: 0.98rem;
  }

  .controls {
    grid-template-columns: 48px 48px 1fr;
  }

  .status {
    font-size: 0.78rem;
  }

  .reader-header {
    align-items: center;
    padding: 18px 16px 12px;
  }

  .reader-header .eyebrow,
  .reader-header p:last-child {
    display: none;
  }

  .reader-header h2 {
    font-size: 2rem;
  }

  .script-page {
    padding: 22px 14px 48px;
  }

  .script-section {
    margin-bottom: 30px;
  }

  .english {
    font-size: calc(1.18rem * var(--page-scale));
    line-height: 1.35;
  }

  .note {
    font-size: calc(1rem * var(--page-scale));
    line-height: 1.35;
  }

  .line-number {
    font-size: calc(1.18rem * var(--page-scale));
  }

  body.has-image-dock {
    --dock-height: min(30svh, 230px);
  }
}
