/* Interactive student workbook — spreadsheet-style fields */

/* Never sticky — must scroll away with page (PC + phone) */
.page-workbook .workbook-bar {
  position: static !important;
  top: auto !important;
  z-index: auto !important;
  max-width: 100%;
  margin: 0 auto 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--card-solid);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 768px) {
  .page-workbook .workbook-bar {
    padding: 0.55rem 0.75rem;
  }
  .page-workbook .page-banner {
    margin-bottom: 0.35rem;
    padding: 0.65rem 0.75rem;
    font-size: 0.82rem;
  }
}

.workbook-bar-hint {
  margin: 0 0 0.6rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.workbook-bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.wb-status {
  font-size: 0.75rem;
  font-weight: 800;
  color: #059669;
  padding: 0.35rem 0.75rem;
  background: rgba(5, 150, 105, 0.1);
  border-radius: 999px;
  margin-right: 0.25rem;
}

.wb-account-sync-hint {
  display: none;
  font-size: 0.72rem;
  font-weight: 600;
  color: #5b21b6;
  padding: 0.3rem 0.65rem;
  background: rgba(91, 33, 182, 0.08);
  border-radius: 999px;
  max-width: 14rem;
  line-height: 1.25;
}

body.account-sync-on .wb-account-sync-hint {
  display: inline-block;
}

.wb-progress {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--violet);
  padding: 0.35rem 0.75rem;
  background: var(--code-bg);
  border-radius: 999px;
}

.wb-btn {
  min-height: 40px;
  padding: 0 1rem;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card-solid);
  border: 1.5px solid var(--border-subtle);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
}

.wb-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  border-color: rgba(109, 40, 217, 0.3);
}

.wb-btn-danger {
  color: #b91c1c;
  border-color: rgba(185, 28, 28, 0.25);
}

/* Exercise cards */
.exercise-sheet {
  margin: 1.5rem 0;
  padding: 0;
  background: var(--card-solid);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.exercise-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  padding: 0.85rem 1.25rem;
  background: linear-gradient(90deg, var(--code-bg), transparent);
  border-bottom: 1px solid var(--border-subtle);
}

.exercise-sheet > h3,
.exercise-head > h3 {
  margin: 0;
  padding: 0;
  font-size: 1rem;
  font-weight: 800;
  flex: 1 1 12rem;
}

.exercise-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.wb-btn-check {
  color: #047857;
  border-color: rgba(4, 120, 87, 0.35);
  background: #ecfdf5;
}

.wb-btn-solution {
  color: var(--violet);
  border-color: rgba(109, 40, 217, 0.35);
  background: var(--code-bg);
}

.wb-check-feedback {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
}

.wb-check-feedback.is-ok {
  color: #059669;
}

.wb-check-feedback.is-warn {
  color: #b45309;
}

.wb-check-feedback.is-err {
  color: #b91c1c;
}

.page-workbook .workbook-field.wb-field-correct {
  border-color: #16a34a !important;
  background: #f0fdf4 !important;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.2);
}

.page-workbook .workbook-field.wb-field-wrong {
  border-color: #dc2626 !important;
  background: #fef2f2 !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.2);
}

.wb-solution-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(15, 13, 26, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.wb-solution-dialog {
  width: min(28rem, 100%);
  max-height: min(70vh, 24rem);
  overflow: auto;
  padding: 1.15rem 1.25rem;
  background: #fff;
  border-radius: var(--radius);
  border: 2px solid rgba(109, 40, 217, 0.35);
  box-shadow: var(--shadow-md, 0 12px 40px rgba(0, 0, 0, 0.18));
}

.wb-solution-dialog h4 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--violet);
}

.wb-solution-dialog pre {
  margin: 0 0 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.55;
  color: #0f0d1a;
}

.wb-solution-dialog .wb-btn {
  width: 100%;
}

.exercise-body {
  padding: 1.15rem 1.25rem 1.35rem;
}

.exercise-body > p:first-child {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 0;
}

/* Student workbook: always light, high contrast (Windows dark mode safe) */
.page-workbook {
  color-scheme: light only;
  --bg: #f8f7ff;
  --text: #0f0d1a;
  --muted: #5b5670;
  --card: #ffffff;
  --card-solid: #ffffff;
  --border-subtle: rgba(15, 13, 26, 0.12);
  --code-bg: rgba(79, 70, 229, 0.08);
  --header-bg: rgba(255, 255, 255, 0.92);
  color: #0f0d1a;
}

.page-workbook .week-panel,
.page-workbook .exercise-sheet,
.page-workbook .workbook-bar,
.page-workbook .page-banner,
.page-workbook .site-header {
  color: #0f0d1a;
}

.page-workbook .week-panel-content,
.page-workbook .exercise-body {
  color: #0f0d1a !important;
}

.page-workbook .exercise-sheet {
  background: #ffffff !important;
  border: 2px solid rgba(109, 40, 217, 0.25) !important;
}

.page-workbook .week-panel {
  background: #ffffff !important;
}

.page-workbook input.workbook-field,
.page-workbook textarea.workbook-field {
  color-scheme: light;
  -webkit-appearance: auto;
  appearance: auto;
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.4;
  color: #0f0d1a;
  background: #ffffff;
  border: 3px solid #6d28d9;
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8), 0 2px 8px rgba(79, 70, 229, 0.2);
  min-height: 2.75rem;
  box-sizing: border-box;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.page-workbook .wb-sync-id,
.page-workbook select {
  color-scheme: light;
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f0d1a;
  background: #ffffff;
  border: 3px solid #6d28d9;
  border-radius: 10px;
  min-height: 2.75rem;
  box-sizing: border-box;
}

.page-workbook .workbook-field:-webkit-autofill,
.page-workbook .workbook-field:-webkit-autofill:hover,
.page-workbook .workbook-field:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px #ffffff inset;
  box-shadow: 0 0 0 1000px #ffffff inset;
  -webkit-text-fill-color: #0f0d1a;
  color: #0f0d1a;
  border: 3px solid #6d28d9;
}

/* Touch-friendly field layout (iOS Safari) */
.wb-field-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0.75rem 0 1rem;
}

.wb-field-line,
.wb-field-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.65rem 0.75rem;
  background: #faf8ff;
  border: 1px solid rgba(109, 40, 217, 0.2);
  border-radius: 10px;
}

.wb-field-prompt,
.wb-field-label {
  font-size: 0.92rem;
  font-weight: 700;
  color: #0f0d1a;
  line-height: 1.45;
}

.wb-field-control {
  display: block;
  width: 100%;
}

.wb-field-control .workbook-field,
.wb-field-line .workbook-field,
.wb-field-row .workbook-field {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 0;
}

.wb-numbered-li {
  list-style: none;
  margin-left: 0 !important;
  padding-left: 0 !important;
}

.page-workbook .spreadsheet td .workbook-field {
  display: block;
  width: 100%;
  min-width: 5rem;
}

.page-workbook .wb-gap {
  min-width: 8em;
  max-width: 100%;
  padding: 0.5em 0.65em;
}

.page-workbook .wb-gap::placeholder,
.page-workbook .wb-notes::placeholder,
.page-workbook .wb-transform::placeholder {
  color: #64748b;
  font-weight: 600;
}

/* Empty answer boxes stand out */
.page-workbook .wb-gap:placeholder-shown,
.page-workbook .wb-notes:placeholder-shown,
.page-workbook .wb-transform:placeholder-shown {
  background: #fffbeb !important;
  border-color: #7c3aed !important;
}

.page-workbook .workbook-field:focus {
  outline: none;
  border-color: #6d28d9 !important;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.25);
}

.page-workbook .wb-transform {
  display: block;
  width: 100%;
  margin: 0.5rem 0 1rem;
  padding: 0.75rem 1rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 3rem;
}

.wb-numbered {
  list-style: none;
  margin-left: 0 !important;
  padding-left: 0 !important;
}

.wb-num {
  display: inline-block;
  min-width: 1.75rem;
  font-weight: 800;
  color: var(--violet);
}

/* Spreadsheet tables */
.spreadsheet {
  width: 100%;
  margin: 1rem 0;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.spreadsheet th,
.spreadsheet td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-subtle);
}

.spreadsheet thead th {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--code-bg);
}

.spreadsheet tbody tr:last-child td,
.spreadsheet tbody tr:last-child th {
  border-bottom: none;
}

.spreadsheet tbody tr:hover td {
  background: rgba(109, 40, 217, 0.04);
}

.homework-sheet td:nth-child(3),
.homework-sheet td:nth-child(4) {
  width: 4.5rem;
  text-align: center;
}

.homework-sheet .wb-notes {
  width: 100%;
  min-width: 8rem;
  font-size: 0.88rem;
}

.homework-sheet .wb-check {
  width: 1.35rem;
  height: 1.35rem;
  accent-color: var(--violet);
  cursor: pointer;
}

.wb-match-table .wb-match {
  width: 3.5rem;
  min-width: 3.5rem;
  text-align: center;
  padding: 0.4rem;
  font-weight: 800;
}

/* Workbook tables: keep real table layout (content table { display:block } breaks mobile taps) */
.page-workbook .spreadsheet,
.page-workbook .wb-match-table,
.page-workbook .homework-sheet {
  display: table !important;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.page-workbook .spreadsheet thead {
  display: table-header-group !important;
}

.page-workbook .spreadsheet tbody {
  display: table-row-group !important;
}

.page-workbook .spreadsheet tr {
  display: table-row !important;
}

.page-workbook .spreadsheet th,
.page-workbook .spreadsheet td {
  display: table-cell !important;
}

.wb-match-key {
  font-weight: 800;
  color: var(--violet);
  width: 2rem;
}

@media (max-width: 768px) {
  .page-workbook input.workbook-field,
  .page-workbook textarea.workbook-field {
    font-size: 16px;
    min-height: 44px;
  }

  .page-workbook .exercise-body p {
    line-height: 1.65;
  }

  .page-workbook .spreadsheet {
    display: block !important;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .page-workbook .spreadsheet thead,
  .page-workbook .spreadsheet tbody {
    display: table !important;
    width: 100%;
    min-width: 20rem;
  }

  .page-workbook .spreadsheet tr {
    display: table-row !important;
  }

  .page-workbook .spreadsheet th,
  .page-workbook .spreadsheet td {
    display: table-cell !important;
  }
}

@media (max-width: 640px) {
  .workbook-bar-actions .wb-btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.5rem);
  }
}

@media print {
  .workbook-bar,
  .wb-progress {
    display: none !important;
  }
  .wb-gap,
  .wb-transform,
  .wb-notes {
    border: 1px solid #999 !important;
    box-shadow: none !important;
  }
}

/* Optional cloud sync panel */
.wb-sync-details {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  width: 100%;
}

.wb-sync-details summary {
  cursor: pointer;
  font-weight: 800;
  font-size: 0.88rem;
  color: var(--violet);
  list-style: none;
}

.wb-sync-details summary::-webkit-details-marker {
  display: none;
}

.wb-sync-details[open] summary {
  margin-bottom: 0.75rem;
}

.wb-sync-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.wb-sync-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.wb-sync-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

.wb-sync-label select,
.wb-sync-id {
  min-height: 42px;
  padding: 0.5rem 0.75rem;
  font-family: var(--font);
  font-size: 0.95rem;
  border: 1.5px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--card-solid);
  color: var(--text);
}

.wb-sync-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.wb-sync-status {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.wb-sync-status.is-ok {
  color: #059669;
}

.wb-sync-status.is-err {
  color: #b91c1c;
}

.wb-sync-help {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
}

.wb-sync-help a {
  color: var(--violet);
  font-weight: 700;
}

.wb-sync-details.is-active summary {
  color: #059669;
}

/* L&R audio players */
.lr-audio-panel {
  margin: 1rem 0 1.25rem;
  padding: 1.1rem 1.2rem;
  background: linear-gradient(135deg, #ecfdf5, #f0fdfa);
  border: 2px solid #34d399;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.lr-audio-heading {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 800;
  color: #047857;
}

.lr-audio-combined {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.lr-audio-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.lr-audio-label {
  flex: 0 0 auto;
  min-width: 7rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #065f46;
}

.lr-audio-item audio {
  flex: 1 1 12rem;
  min-width: 10rem;
  max-width: 100%;
  height: 2.5rem;
}

.lr-audio-lines {
  margin-top: 0.85rem;
}

.lr-audio-lines summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
  color: #047857;
}

.lr-audio-line-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.lr-audio-missing {
  margin: 0;
  font-size: 0.88rem;
  color: #92400e;
  background: #fffbeb;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid #fcd34d;
}

.lr-audio-missing code {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
}
