:root {
  --ink: #17212b;
  --muted: #66717f;
  --bg: #f6f3ec;
  --panel: #fffdf8;
  --line: #ddd7ca;
  --teal: #176f6b;
  --teal-dark: #0f4f4c;
  --rose: #bc4b51;
  --gold: #d79a2b;
  --violet: #7a5da8;
  --green-soft: #e7f3ee;
  --gold-soft: #fff3d9;
  --rose-soft: #fde9e5;
  --shadow: 0 18px 42px rgba(23, 33, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body.app-shell {
  min-height: 100vh;
  margin: 0;
  font-size: 18px;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(246, 243, 236, 0.68), rgba(246, 243, 236, 0.82)),
    url("assets/site-background.png");
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
  color: var(--ink);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

.login-view,
.status-view {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card,
.status-panel {
  display: grid;
  gap: 20px;
  width: min(100%, 520px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: var(--shadow);
}

.brand-hero {
  display: grid;
  gap: 16px;
  text-align: center;
}

.brand-hero p,
.brand-inline p,
.brand-inline small,
.brand-hero small {
  display: block;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.55;
}

.brand-hero small,
.brand-inline small {
  color: var(--teal-dark);
  font-weight: 900;
}

.brand-logos,
.brand-inline-logos {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.brand-logos {
  min-height: 92px;
}

.brand-logos img,
.brand-inline-logos img {
  display: block;
  object-fit: contain;
}

.brand-logos .school-logo {
  width: 84px;
  height: 84px;
}

.brand-logos .alibaba-logo {
  width: 156px;
  max-height: 76px;
}

.brand-inline {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-inline-logos {
  flex: 0 0 auto;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(221, 215, 202, 0.85);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
}

.brand-inline-logos .school-logo {
  width: 52px;
  height: 52px;
}

.brand-inline-logos .alibaba-logo {
  width: 108px;
  max-height: 48px;
}

.login-card h1,
.status-panel h1,
.topbar h1 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

.login-card h1,
.brand-hero h1 {
  font-size: 36px;
}

.workspace,
.reader-page {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(100%, 1180px);
  margin: 0 auto 16px;
}

.topbar h1 {
  font-size: 34px;
}

.top-actions,
.form-actions,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  width: min(100%, 1180px);
  margin: 0 auto;
}

.editor-main,
.reference-panel,
.reader-surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor-main {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.reference-panel {
  align-self: start;
  padding: 18px;
}

.reference-title {
  margin-bottom: 12px;
  color: var(--rose);
  font-weight: 900;
}

.reference-panel dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

.reference-panel dt {
  color: var(--ink);
  font-weight: 900;
}

.reference-panel dd {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.section-heading {
  color: var(--muted);
  font-size: 18px;
  font-weight: 900;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input {
  min-height: 54px;
  padding: 0 14px;
  font-size: 18px;
}

.field textarea {
  min-height: 220px;
  resize: vertical;
  padding: 16px;
  font-size: 19px;
  line-height: 1.8;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 111, 107, 0.16);
}

.section-block {
  display: grid;
  gap: 10px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.section-heading small {
  color: var(--muted);
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.segmented input,
.style-option input,
.value-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span,
.style-option span,
.value-option span {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.segmented span {
  place-items: center;
  min-height: 56px;
  padding: 0 10px;
  text-align: center;
  font-size: 18px;
  font-weight: 900;
}

.segmented input:checked + span,
.style-option input:checked + span,
.value-option input:checked + span {
  border-color: var(--teal);
  background: var(--green-soft);
  box-shadow: inset 0 0 0 2px rgba(23, 111, 107, 0.08);
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.style-option span {
  min-height: 92px;
  padding: 12px;
  gap: 6px;
}

.style-option strong,
.value-option strong {
  font-size: 18px;
}

.style-option small,
.value-option small {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.value-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.value-option span {
  min-height: 74px;
  padding: 10px;
  gap: 4px;
}

.switch-line {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  color: var(--ink);
  font-weight: 900;
}

.switch-line input {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
}

.btn {
  min-height: 52px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 18px;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

.btn.primary {
  background: var(--teal);
  color: #fff;
}

.btn.primary:hover {
  background: var(--teal-dark);
}

.btn.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.btn.ghost {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.form-actions {
  justify-content: flex-end;
}

.message {
  min-height: 24px;
  margin: 0;
  color: var(--rose);
  font-weight: 900;
}

.quota-chip {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  border: 1px solid #a8d8cf;
  border-radius: 999px;
  background: #e7f6f1;
  color: var(--teal-dark);
  padding: 0 14px;
  font-size: 16px;
  font-weight: 900;
  white-space: nowrap;
}

.quota-chip.neutral {
  border-color: #d8d0c4;
  background: #f7efe3;
  color: #80602a;
}

.quota-chip.danger {
  border-color: #efb1aa;
  background: var(--rose-soft);
  color: #92343a;
}

.status-panel {
  width: min(100%, 520px);
  text-align: center;
}

.status-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 20px;
  font-weight: 800;
}

.progress-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4ded4;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--rose));
  transition: width 260ms ease;
}

.reader-surface {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 16px;
}

.book-spread {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf5;
  transform-origin: center left;
}

.book-spread.turn-next {
  animation: pageFlipNext 420ms ease;
}

.book-spread.turn-prev {
  animation: pageFlipPrev 420ms ease;
}

@keyframes pageFlipNext {
  0% {
    opacity: 0.55;
    transform: perspective(1200px) rotateY(-10deg) translateX(18px);
  }
  100% {
    opacity: 1;
    transform: perspective(1200px) rotateY(0deg) translateX(0);
  }
}

@keyframes pageFlipPrev {
  0% {
    opacity: 0.55;
    transform: perspective(1200px) rotateY(10deg) translateX(-18px);
  }
  100% {
    opacity: 1;
    transform: perspective(1200px) rotateY(0deg) translateX(0);
  }
}

.book-image {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  width: 100%;
  overflow: hidden;
  background: linear-gradient(150deg, #e3f0ea, #f7dece);
}

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

.book-text {
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 30px 38px 36px;
  overflow-y: auto;
}

.page-label {
  color: var(--rose);
  font-weight: 900;
}

.book-text h2 {
  margin: 0;
  font-size: 38px;
  line-height: 1.25;
}

.book-text p {
  margin: 0;
  font-size: 29px;
  line-height: 1.75;
}

.question-box {
  display: grid;
  gap: 8px;
  border-left: 5px solid var(--gold);
  border-radius: 6px;
  background: var(--gold-soft);
  padding: 14px;
}

.question-box strong {
  color: #9c4a2f;
}

.question-box span {
  font-size: 23px;
  line-height: 1.65;
}

.reader-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.language-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.language-tabs button {
  min-width: 58px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 9px 13px;
  font-weight: 900;
  cursor: pointer;
}

.language-tabs button.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.language-tabs span {
  color: var(--muted);
  font-weight: 800;
}

.history-panel {
  margin-top: 18px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.history-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.history-card strong {
  font-size: 21px;
}

.history-card small {
  color: var(--muted);
  font-weight: 800;
}

.history-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.page-dots {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.page-dots button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  font-size: 17px;
  cursor: pointer;
}

.page-dots button.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

@media (max-width: 1180px) and (max-height: 950px) {
  body.app-shell:has(.reader-page) {
    overflow: hidden;
  }

  .reader-page {
    --reader-image-max-height: 42svh;
    --reader-image-max-width: 74svh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    height: 100svh;
    min-height: 100vh;
    min-height: 100svh;
    overflow: hidden;
    padding: 8px 10px;
  }

  .reader-page .topbar {
    gap: 8px;
    margin-bottom: 6px;
  }

  .reader-page .brand-inline {
    gap: 8px;
  }

  .reader-page .brand-inline p {
    display: none;
  }

  .reader-page .brand-inline small {
    max-width: 42vw;
    margin-top: 2px;
    overflow: hidden;
    font-size: 13px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reader-page .brand-inline-logos {
    gap: 6px;
    padding: 4px 6px;
  }

  .reader-page .brand-inline-logos .school-logo {
    width: 34px;
    height: 34px;
  }

  .reader-page .brand-inline-logos .alibaba-logo {
    width: 76px;
    max-height: 34px;
  }

  .reader-page .topbar h1 {
    font-size: 20px;
  }

  .reader-page .top-actions,
  .reader-page .button-row,
  .reader-page .page-dots {
    flex-wrap: nowrap;
  }

  .reader-page .btn {
    min-height: 36px;
    padding: 0 10px;
    font-size: 14px;
  }

  .reader-surface {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 6px;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
    padding: 8px;
  }

  .language-tabs {
    gap: 6px;
    margin-bottom: 0;
  }

  .language-tabs button {
    min-width: 48px;
    padding: 5px 9px;
    font-size: 14px;
  }

  .language-tabs span {
    font-size: 13px;
  }

  .book-spread {
    min-height: 0;
  }

  .book-image {
    width: min(100%, var(--reader-image-max-width));
    max-height: var(--reader-image-max-height);
    justify-self: center;
  }

  .book-text {
    gap: 6px;
    overflow: hidden;
    padding: 10px 14px 12px;
  }

  .page-label {
    font-size: 13px;
  }

  .book-text h2 {
    font-size: clamp(20px, 2.4vw, 25px);
    line-height: 1.16;
  }

  .book-text p {
    font-size: clamp(17px, 2.1vw, 22px);
    line-height: 1.38;
  }

  .question-box {
    gap: 3px;
    border-left-width: 3px;
    padding: 8px 10px;
  }

  .question-box span {
    font-size: clamp(14px, 1.8vw, 18px);
    line-height: 1.35;
  }

  .reader-controls {
    gap: 6px;
    margin-top: 0;
    flex-wrap: nowrap;
  }

  .button-row,
  .page-dots {
    gap: 6px;
  }

  .page-dots {
    gap: 4px;
  }

  .page-dots button {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .reader-page .message {
    min-height: 16px;
    font-size: 13px;
    line-height: 1.2;
  }
}

@media (max-width: 1180px) and (max-height: 950px) and (orientation: landscape) {
  .reader-page {
    --reader-image-max-height: 39svh;
    --reader-image-max-width: 69svh;
  }
}

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

  .book-spread {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .workspace,
  .reader-page {
    padding: 14px;
  }

  .topbar,
  .reader-controls {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .brand-inline-logos {
    width: 100%;
    justify-content: flex-start;
  }

  .segmented,
  .style-grid,
  .value-grid {
    grid-template-columns: 1fr;
  }

  .book-text {
    padding: 22px;
  }

  .book-text h2 {
    font-size: 30px;
  }

  .book-text p {
    font-size: 24px;
    line-height: 1.75;
  }
}
