:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #eef6f3;
  --text: #1d2522;
  --muted: #61716b;
  --line: #dbe4df;
  --primary: #087f67;
  --primary-dark: #05614f;
  --accent: #d78b28;
  --disabled: #a8b3af;
  --shadow: 0 18px 45px rgba(31, 53, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

button,
audio,
input {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.start-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(8, 127, 103, 0.12), transparent 45%),
    var(--bg);
}

.start-panel {
  width: min(100%, 500px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 30px;
}

.start-panel h1 {
  margin: 0;
  font-size: clamp(2.2rem, 8vw, 4rem);
  line-height: 1;
}

.start-copy {
  margin: 14px 0 24px;
  color: var(--muted);
  line-height: 1.55;
}

.name-form {
  display: grid;
  gap: 10px;
}

.name-form label {
  font-weight: 800;
}

.name-form input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: #fff;
}

.name-form input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(8, 127, 103, 0.16);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: #a93b2f;
  font-size: 0.92rem;
}

.start-button {
  border: 0;
  border-radius: 8px;
  min-height: 50px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

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

.sidebar {
  background: #11382f;
  color: #fff;
  padding: 28px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

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

.brand h1,
.hero h2,
.lesson-panel h3 {
  margin: 0;
}

.student-pill {
  display: inline-flex;
  max-width: 100%;
  margin: 10px 0 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  padding: 7px 10px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.86rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 6px;
  color: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  opacity: 0.72;
}

.module-nav {
  display: grid;
  gap: 16px;
}

.nav-group {
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  padding-bottom: 14px;
}

.group-title,
.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
}

.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px;
  background: transparent;
  color: #fff;
  font-weight: 700;
}

.group-title[aria-expanded="false"] .chevron {
  transform: rotate(-90deg);
}

.chevron {
  transition: transform 180ms ease;
}

.submenu {
  display: none;
  gap: 8px;
  padding: 8px 0 0;
}

.submenu.is-open {
  display: grid;
}

.nav-item {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78);
}

.nav-item.is-active {
  background: #fff;
  color: #11382f;
  font-weight: 800;
}

.nav-item:disabled {
  color: rgba(255, 255, 255, 0.42);
  cursor: not-allowed;
}

.content {
  padding: 34px;
  min-width: 0;
}

.hero {
  margin-bottom: 26px;
}

.hero h2 {
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 1;
}

.hero p {
  max-width: 720px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.meta-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--primary-dark);
  padding: 8px 12px;
  font-weight: 800;
}

.student-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px 14px;
}

.student-banner span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.student-banner strong {
  font-size: 1.05rem;
}

.student-banner button {
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 36px;
  background: #fff;
  color: var(--primary-dark);
  cursor: pointer;
  font-weight: 800;
  padding: 0 12px;
}

.lesson-panel,
.step-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  align-items: start;
}

.lesson-panel {
  padding: 28px;
  min-width: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.lesson-panel h3 {
  font-size: clamp(1.7rem, 3vw, 2.5rem);
}

.step-count {
  align-self: start;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--primary-dark);
  padding: 8px 12px;
  font-weight: 800;
  white-space: nowrap;
}

.arabic {
  margin: 0 0 18px;
  direction: rtl;
  font-family: "Traditional Arabic", "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.45;
}

.meaning {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.65;
  white-space: pre-line;
}

.detail-list {
  display: grid;
  gap: 10px;
  margin: -8px 0 26px;
  padding: 0;
  list-style: none;
}

.detail-list li {
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 14px;
  line-height: 1.55;
}

.image-panel {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 260px;
  margin: 0 0 24px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  overflow: hidden;
}

.image-panel.has-image {
  border-style: solid;
  background: #fff;
}

.image-gallery {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  padding: 12px;
}

.image-panel.has-image .image-gallery {
  display: grid;
}

.step-image-item {
  display: grid;
  gap: 8px;
  align-content: start;
}

.step-image-item img {
  display: block;
  width: 100%;
  height: min(36vw, 360px);
  border-radius: 8px;
  background: var(--surface-2);
  object-fit: contain;
}

.step-image-item span {
  color: var(--primary-dark);
  text-align: center;
  font-size: 0.92rem;
  font-weight: 800;
}

.image-panel figcaption {
  padding: 0 16px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.image-panel.has-image figcaption {
  padding-bottom: 14px;
}

.audio-box {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
  padding: 16px;
  border-radius: 8px;
  background: var(--surface-2);
}

#lessonAudioList {
  display: grid;
  gap: 10px;
}

.lesson-audio-item {
  display: grid;
  gap: 8px;
}

.lesson-audio-item strong {
  color: var(--primary-dark);
}

.audio-box audio {
  width: 100%;
}

.audio-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.control-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 700;
}

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

.control-btn:disabled {
  color: var(--disabled);
  cursor: not-allowed;
}

.step-list {
  display: grid;
  gap: 10px;
  padding: 14px;
  min-width: 0;
}

.step-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 26px;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.step-button.is-selected {
  border-color: var(--primary);
  background: var(--surface-2);
}

.step-number,
.done-mark {
  display: grid;
  place-items: center;
  font-weight: 800;
}

.step-number {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #e9eee9;
  color: var(--primary-dark);
}

.step-name {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.done-mark {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  color: transparent;
  background: #edf1ef;
}

.step-button.is-done .done-mark {
  color: #fff;
  background: var(--primary);
}

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

  .sidebar {
    padding: 22px;
  }

  .content {
    padding: 22px;
  }

  .workspace {
    gap: 16px;
  }

  .step-list {
    order: -1;
  }
}

@media (max-width: 700px) {
  .sidebar {
    position: static;
    padding: 14px;
  }

  .brand {
    gap: 10px;
    margin-bottom: 14px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 8px;
  }

  .brand h1 {
    font-size: 1.05rem;
  }

  .module-nav {
    gap: 8px;
  }

  .nav-group {
    padding-bottom: 8px;
  }

  .group-title {
    min-height: 42px;
    padding: 8px;
  }

  .submenu {
    grid-template-columns: 1fr;
    gap: 6px;
    padding-top: 6px;
  }

  .nav-item {
    min-height: 42px;
    padding: 10px 12px;
  }

  .content {
    padding: 16px;
  }

  .hero {
    margin-bottom: 16px;
  }

  .hero h2 {
    font-size: 2.35rem;
  }

  .hero p {
    font-size: 0.98rem;
    line-height: 1.5;
  }

  .meta-row {
    gap: 8px;
  }

  .meta-row span {
    padding: 7px 10px;
    font-size: 0.86rem;
  }

  .student-banner {
    display: grid;
    gap: 6px;
  }

  .student-banner button {
    width: 100%;
    margin-left: 0;
  }

  .step-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
  }

  .step-button {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    min-width: 0;
    min-height: 78px;
    border-width: 1px 1px 4px;
    padding: 8px 6px;
    text-align: center;
  }

  .step-number {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    font-size: 0.85rem;
  }

  .step-name {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.76rem;
    line-height: 1.18;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .done-mark {
    display: none;
  }

  .step-button.is-selected {
    border-bottom-color: var(--primary);
    background: var(--surface-2);
  }

  .lesson-panel {
    padding: 18px;
  }

  .panel-header {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
  }

  .step-count {
    justify-self: start;
  }

  .lesson-panel h3 {
    font-size: 1.65rem;
    line-height: 1.15;
  }

  .arabic {
    font-size: 2rem;
    line-height: 1.55;
  }

  .meaning {
    margin-bottom: 20px;
    font-size: 1rem;
    line-height: 1.55;
  }

  .detail-list {
    margin-bottom: 20px;
  }

  .image-panel {
    min-height: 200px;
    margin-bottom: 20px;
  }

  .image-gallery {
    grid-template-columns: 1fr;
  }

  .step-image-item img {
    height: auto;
    max-height: 320px;
  }

  .detail-list li,
  .audio-box {
    padding: 12px;
  }

  .lesson-audio-item strong {
    font-size: 0.95rem;
  }

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

  .control-btn {
    min-height: 48px;
    padding: 0 12px;
  }

  .control-btn.primary {
    grid-column: 1 / -1;
    order: -1;
  }
}

@media (max-width: 560px) {
  .brand {
    align-items: flex-start;
  }

}

@media (max-width: 390px) {
  .start-screen {
    padding: 14px;
  }

  .start-panel {
    padding: 20px;
  }

  .content {
    padding: 12px;
  }

  .hero h2 {
    font-size: 2rem;
  }

  .lesson-panel {
    padding: 14px;
  }

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

  .control-btn.primary {
    order: 0;
  }
}

@media (max-width: 350px) {
  .step-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
