:root {
  color-scheme: light;
  --ink: #152027;
  --muted: #60717a;
  --line: #d8e4e8;
  --paper: #eef4f7;
  --panel: #ffffff;
  --accent: #00a6c8;
  --accent-dark: #04738d;
  --cyan: #12d6f3;
  --navy: #0d1b2a;
  --navy-2: #12263a;
  --gold: #f2b84b;
  --rose: #d85c75;
  --blue: #3f7df5;
  --soft-green: #e7f9fb;
  --soft-gold: #fff7e5;
  --soft-blue: #edf5ff;
  --shadow: 0 18px 44px rgba(13, 27, 42, 0.13);
  --glow: 0 0 0 1px rgba(18, 214, 243, 0.16), 0 18px 44px rgba(0, 77, 109, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(0, 166, 200, 0.12), transparent 34%),
    linear-gradient(320deg, rgba(63, 125, 245, 0.10), transparent 38%),
    var(--paper);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(120deg, rgba(18, 214, 243, 0.18), transparent 42%),
    linear-gradient(320deg, rgba(63, 125, 245, 0.18), transparent 46%),
    radial-gradient(circle at 70% 20%, rgba(242, 184, 75, 0.18), transparent 30%),
    #eaf2f7;
}

.login-shell {
  width: min(1040px, 100%);
  min-height: 620px;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--glow);
}

.brand-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 56px;
  color: #fff;
  background:
    linear-gradient(rgba(7, 17, 28, 0.24), rgba(7, 17, 28, 0.84)),
    linear-gradient(90deg, rgba(18, 214, 243, 0.22) 1px, transparent 1px),
    linear-gradient(0deg, rgba(18, 214, 243, 0.16) 1px, transparent 1px),
    radial-gradient(circle at 26% 22%, rgba(18, 214, 243, 0.30), transparent 24%),
    linear-gradient(140deg, #0d1b2a, #12385c 55%, #096d86);
  background-size: auto, 36px 36px, 36px 36px, auto, auto;
}

.brand-panel h1 {
  margin: 8px 0 18px;
  font-size: 46px;
  line-height: 1.16;
  letter-spacing: 0;
}

.brand-panel p {
  max-width: 560px;
  line-height: 1.8;
}

.login-panel {
  padding: 48px;
  align-self: center;
}

.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 26px;
}

.login-tab,
.ghost-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 11px 14px;
}

.login-tab.active,
.ghost-button.active {
  border-color: var(--accent);
  background: var(--soft-green);
  color: var(--accent-dark);
  font-weight: 700;
}

.login-form {
  display: grid;
  gap: 18px;
}

label,
.wide-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  color: var(--ink);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 4px rgba(0, 166, 200, 0.13);
}

textarea {
  resize: vertical;
  line-height: 1.7;
}

.primary-button,
.danger-button {
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  font-weight: 800;
  box-shadow: 0 12px 22px rgba(0, 120, 170, 0.24);
}

.primary-button:hover {
  background: linear-gradient(135deg, var(--accent-dark), #285ed1);
}

.danger-button {
  background: var(--rose);
}

.hint,
.error-message {
  min-height: 1.5em;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.error-message {
  color: var(--rose);
  font-weight: 700;
}

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid rgba(18, 214, 243, 0.22);
  background:
    linear-gradient(90deg, rgba(18, 214, 243, 0.09) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, var(--navy), var(--navy-2));
  background-size: 28px 28px, 28px 28px, auto;
  color: #eaf8fb;
}

.sidebar-head {
  padding: 28px 24px 18px;
}

.sidebar-head h2,
.topbar h2 {
  margin: 0;
  font-size: 22px;
}

.sidebar-head h2 {
  color: #ffffff;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar .eyebrow {
  color: var(--cyan);
}

.chapter-nav {
  display: grid;
  gap: 8px;
  padding: 0 16px 24px;
}

.chapter-group {
  border: 1px solid rgba(18, 214, 243, 0.22);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18);
}

.chapter-button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 14px;
  text-align: left;
  color: #eaf8fb;
  font-weight: 900;
}

.chapter-button.active {
  background: linear-gradient(135deg, rgba(18, 214, 243, 0.20), rgba(63, 125, 245, 0.18));
  color: #ffffff;
  box-shadow: inset 4px 0 0 var(--cyan);
}

.subchapter-list {
  display: none;
  padding: 8px;
  border-top: 1px solid rgba(18, 214, 243, 0.16);
}

.chapter-group.open .subchapter-list {
  display: grid;
  gap: 6px;
}

.subchapter-button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 10px;
  background: transparent;
  color: #b7cbd4;
  text-align: left;
}

.subchapter-button.active,
.subchapter-button:hover {
  background: rgba(18, 214, 243, 0.12);
  color: #ffffff;
  font-weight: 700;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 252, 254, 0.92);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(13, 27, 42, 0.06);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 24px;
  padding: 32px;
}

.lesson-panel,
.worksheet-panel,
.teacher-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 34px rgba(13, 27, 42, 0.08);
}

.lesson-panel {
  padding: 34px;
  border-top: 5px solid var(--accent);
}

.worksheet-panel {
  position: sticky;
  top: 92px;
  max-height: calc(100vh - 116px);
  overflow: auto;
  padding: 22px;
}

.lesson-title {
  margin: 0 0 12px;
  font-size: 32px;
  line-height: 1.28;
  color: #102033;
}

.lesson-richtext {
  color: #243034;
}

.lesson-richtext h2,
.lesson-richtext h3 {
  margin: 26px 0 12px;
  color: #102f4a;
}

.lesson-richtext p,
.lesson-richtext li {
  line-height: 1.9;
}

.lesson-richtext blockquote {
  margin: 18px 0;
  padding: 14px 16px;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--soft-blue), #ffffff);
}

.lesson-richtext figure {
  margin: 22px 0;
}

.lesson-richtext img,
.lesson-editor img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.video-embed {
  overflow: hidden;
  border: 1px solid rgba(0, 166, 200, 0.22);
  border-radius: 8px;
  background: #0d1b2a;
  box-shadow: 0 16px 34px rgba(13, 27, 42, 0.14);
}

.video-embed iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
}

.lesson-richtext figcaption,
.lesson-editor figcaption {
  margin-top: 7px;
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  color: #07576d;
  background: var(--soft-green);
  font-size: 13px;
  font-weight: 800;
  border: 1px solid rgba(0, 166, 200, 0.18);
}

.formula-box {
  margin: 18px 0;
  padding: 18px;
  border: 1px solid rgba(0, 166, 200, 0.24);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(231, 249, 251, 0.92), rgba(255, 247, 229, 0.72)),
    #ffffff;
}

.formula-card {
  margin: 14px 0 18px;
}

.formula {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px;
  padding: 18px 12px;
  border-radius: 8px;
  color: #111f22;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.16) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.16) 1px, transparent 1px),
    linear-gradient(135deg, #dff8ee, #dff3ff);
  background-size: 24px 24px, 24px 24px, auto;
  font-family: "Cambria Math", "Times New Roman", serif;
  font-size: 28px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(0, 166, 200, 0.18);
}

.fraction {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  min-width: 42px;
  line-height: 1.1;
  vertical-align: middle;
}

.fraction .top {
  width: 100%;
  padding: 0 8px 4px;
  border-bottom: 2px solid currentColor;
  text-align: center;
}

.fraction .bottom {
  padding: 4px 8px 0;
  text-align: center;
}

.formula-meanings {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0 0 0 20px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
}

.lesson-section {
  margin-top: 26px;
  padding: 2px 0;
}

.lesson-section h3,
.worksheet-panel h3,
.teacher-section h3 {
  margin: 0 0 12px;
  font-size: 21px;
  color: #102f4a;
}

.lesson-section li,
.lesson-section p {
  line-height: 1.9;
}

.lesson-section ul {
  padding-left: 22px;
}

.lesson-section li::marker {
  color: var(--accent);
}

.worksheet-form {
  display: grid;
  gap: 18px;
}

.password-panel {
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid rgba(0, 166, 200, 0.22);
  border-radius: 8px;
  background: linear-gradient(135deg, #ffffff, #eefaff);
  box-shadow: 0 10px 22px rgba(13, 27, 42, 0.06);
}

.password-panel h3 {
  margin-bottom: 8px;
}

.password-form {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.question-card {
  padding: 15px;
  border: 1px solid rgba(0, 166, 200, 0.18);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f7fbfd);
  box-shadow: 0 8px 18px rgba(13, 27, 42, 0.04);
}

.question-card p {
  margin: 0 0 12px;
  line-height: 1.7;
  font-weight: 800;
  color: #142b3d;
}

.choice-list {
  display: grid;
  gap: 8px;
}

.choice-list label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--ink);
  font-weight: 500;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.choice-list label:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 16px rgba(0, 166, 200, 0.10);
  transform: translateY(-1px);
}

.choice-list input {
  width: auto;
  margin-top: 4px;
  accent-color: var(--accent);
}

.save-state {
  color: var(--blue);
  font-size: 14px;
  font-weight: 800;
}

.teacher-view {
  display: grid;
  gap: 22px;
  padding: 32px;
}

.teacher-section {
  padding: 24px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.teacher-form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.editor-section {
  border-top: 5px solid var(--accent);
}

.editor-selectors {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(220px, 1.1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid rgba(0, 166, 200, 0.18);
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fdff, #eef8fb);
}

.editor-toolbar button,
.image-upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.image-upload-button input {
  display: none;
}

.lesson-editor {
  min-height: 420px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8), 0 10px 24px rgba(13, 27, 42, 0.05);
}

.lesson-editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(31, 122, 109, 0.12);
}

.lesson-editor h2,
.lesson-editor h3 {
  color: #173f3b;
}

.lesson-editor p,
.lesson-editor li {
  line-height: 1.9;
}

.lesson-editor blockquote {
  margin: 18px 0;
  padding: 14px 16px;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: var(--soft-blue);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  background: #f4f9fb;
}

.answer-list {
  display: grid;
  gap: 14px;
}

.answer-card {
  border: 1px solid rgba(0, 166, 200, 0.18);
  border-radius: 8px;
  padding: 18px;
  background: linear-gradient(180deg, #ffffff, #f7fbfd);
}

.answer-card h4,
.answer-card p {
  margin: 0 0 10px;
}

.answer-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.score-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 12px;
  color: #07576d;
  background: var(--soft-green);
  border: 1px solid rgba(0, 166, 200, 0.18);
}

.answer-item {
  margin: 10px 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.answer-item strong {
  display: block;
  margin-bottom: 5px;
}

.grade-control {
  display: inline-grid;
  grid-template-columns: auto 96px;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.grade-control select {
  padding: 8px 10px;
}

@media (max-width: 980px) {
  .login-shell,
  .app-view,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .brand-panel {
    min-height: 320px;
    padding: 36px;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .chapter-nav {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }

  .worksheet-panel {
    position: relative;
    top: auto;
    max-height: none;
  }
}

@media (max-width: 700px) {
  .login-view,
  .content-grid,
  .teacher-view {
    padding: 16px;
  }

  .login-panel,
  .lesson-panel,
  .teacher-section {
    padding: 20px;
  }

  .brand-panel h1,
  .lesson-title {
    font-size: 30px;
  }

  .topbar,
  .section-title,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .teacher-form-grid {
    grid-template-columns: 1fr;
  }

  .editor-selectors {
    grid-template-columns: 1fr;
  }
}
