/* ---------- Parent dashboard ---------- */
#parent-overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 16, 32, 0.75);
  padding: 16px;
}
#parent-overlay.hidden { display: none; }

#parent-card {
  width: min(860px, 96vw);
  max-height: min(88vh, 720px);
  background: #f8fbfd;
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

#parent-pin-gate {
  padding: 32px;
  text-align: center;
}
#parent-pin-gate h2 { margin: 0 0 8px; color: #1d3557; }
#parent-pin-gate p { color: #6b7f95; margin: 0 0 18px; }
#parent-pin-input {
  width: 140px;
  font-size: 28px;
  text-align: center;
  letter-spacing: 8px;
  padding: 10px;
  border: 2px solid #d8e4ee;
  border-radius: 12px;
  margin-bottom: 12px;
}
#parent-pin-msg { color: #e63946; min-height: 20px; margin-bottom: 12px; }

#parent-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#parent-panel.hidden { display: none; }

#parent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #fff;
  border-bottom: 1px solid #e6eef5;
}
#parent-head h2 { margin: 0; font-size: 18px; color: #1d3557; }
#parent-close-panel {
  background: none;
  border: none;
  font-size: 20px;
  color: #8aa0b4;
  cursor: pointer;
  padding: 4px 8px;
}
#parent-close-panel:hover { color: #1d3557; }

#parent-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 18px 0;
  background: #fff;
  border-bottom: 1px solid #e6eef5;
}
.parent-tab {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  color: #6b7f95;
  cursor: pointer;
  border-radius: 10px 10px 0 0;
  border-bottom: 3px solid transparent;
}
.parent-tab.active {
  color: #1d3557;
  border-bottom-color: #2ec4b6;
  background: #f0f7f6;
}

.parent-tab-pane {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  touch-action: pan-y;
}
.parent-tab-pane.hidden { display: none; }

/* —— Parent overview (auto-generated from attempts) —— */
.parent-overview-root {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.po-empty {
  text-align: center;
  padding: 32px 16px;
  background: #fff;
  border: 1px dashed #c8d8e6;
  border-radius: 14px;
}
.po-empty-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  color: #1d3557;
}
.po-empty-text {
  margin: 0;
  font-size: 14px;
  color: #6b7f95;
  line-height: 1.5;
}

.po-hero {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.po-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.po-stat {
  background: #fff;
  border: 1px solid #e6eef5;
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}
.po-stat span {
  display: block;
  font-size: 24px;
  font-weight: 800;
  color: #1d3557;
}
.po-stat label {
  font-size: 12px;
  color: #6b7f95;
}
.po-insight {
  background: #eef6fc;
  border: 1px solid #cfe3f2;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.55;
  color: #1d3557;
}

.po-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.po-chip {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.po-chip-good {
  background: #e8f8ef;
  color: #1b7a4a;
  border: 1px solid #b8e6cc;
}
.po-chip-warn {
  background: #fff4e8;
  color: #b45309;
  border: 1px solid #fcd9a8;
}

.po-subject {
  background: #fff;
  border: 1px solid #d7e3ee;
  border-radius: 14px;
  overflow: hidden;
}
.po-subject-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #e8f2fa;
  border-bottom: 1px solid #d7e3ee;
}
.po-subject-head h3 {
  margin: 0;
  font-size: 16px;
  color: #1d3557;
}
.po-subject-meta {
  font-size: 12px;
  color: #457b9d;
  white-space: nowrap;
}

.po-topic {
  padding: 12px 14px;
  border-bottom: 1px solid #eef3f7;
}
.po-topic:last-child {
  border-bottom: none;
}
.po-topic-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.po-topic-head h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #2a6f97;
}
.po-topic-head span {
  font-size: 12px;
  color: #6b7f95;
  white-space: nowrap;
}

.po-skills {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.po-skill {
  border: 1px solid #e4edf5;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fafcfe;
}
.po-skill-good { border-left: 3px solid #2a9d6f; }
.po-skill-rising { border-left: 3px solid #457b9d; }
.po-skill-learning { border-left: 3px solid #6b7f95; }
.po-skill-needs_help { border-left: 3px solid #e76f51; }
.po-skill-new { border-left: 3px solid #adb5bd; }

.po-skill-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.po-skill-name {
  font-size: 14px;
  font-weight: 700;
  color: #1d3557;
}
.po-skill-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef3f7;
  color: #457b9d;
  white-space: nowrap;
}
.po-skill-needs_help .po-skill-badge {
  background: #fdeee8;
  color: #c4451a;
}
.po-skill-good .po-skill-badge {
  background: #e8f8ef;
  color: #1b7a4a;
}

.po-skill-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 12px;
  color: #6b7f95;
  margin-bottom: 8px;
}

.po-bar {
  height: 6px;
  background: #e8f0f7;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.po-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #457b9d, #2a9d6f);
  border-radius: 999px;
}

.po-skill-adaptive {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 12px;
  color: #457b9d;
}
.po-skill-adaptive strong {
  color: #1d3557;
}
.po-streak {
  color: #8aa0b4;
}

.po-section-title {
  margin: 0 0 10px;
  font-size: 14px;
  color: #1d3557;
}
.po-mastery-log {
  background: #fff;
  border: 1px solid #d7e3ee;
  border-radius: 14px;
  padding: 12px 14px;
}
.po-mastery-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.po-mastery-item {
  border: 1px solid #e6eef5;
  border-radius: 10px;
  padding: 8px 10px;
  background: #fafcfe;
}
.po-mastery-promote-fast,
.po-mastery-promote-slow {
  border-left: 3px solid #2a9d6f;
}
.po-mastery-demote {
  border-left: 3px solid #e76f51;
}
.po-mastery-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.po-mastery-badge {
  font-size: 11px;
  font-weight: 700;
  color: #1d3557;
}
.po-mastery-when {
  font-size: 11px;
  color: #8aa0b4;
  white-space: nowrap;
}
.po-mastery-main {
  font-size: 13px;
  font-weight: 700;
  color: #2a6f97;
  margin-bottom: 2px;
}
.po-mastery-detail {
  font-size: 12px;
  color: #457b9d;
  line-height: 1.4;
}

.po-chips-inline {
  padding: 0 14px 10px;
}
.po-subsection-title {
  margin: 0 0 8px;
  font-size: 13px;
  color: #457b9d;
}
.po-mastery-log-inline {
  margin: 0 14px 12px;
  padding: 10px 12px;
  background: #f7fbfe;
  border: 1px solid #e6eef5;
  border-radius: 10px;
}
.po-subject + .po-subject {
  margin-top: 8px;
}

.parent-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.parent-subject-cell {
  min-width: 120px;
  font-size: 12px;
  line-height: 1.45;
}
.parent-meta-line {
  color: #457b9d;
}
.parent-meta-sub {
  color: #2a6f97;
  font-weight: 600;
}
.parent-meta-muted {
  color: #adb5bd;
}
.parent-chosen {
  min-width: 56px;
  font-weight: 600;
}
.parent-mastery-cell {
  min-width: 160px;
  font-size: 11px;
  line-height: 1.35;
}
.parent-mastery-up {
  color: #1b7a4a;
}
.parent-mastery-down {
  color: #c4451a;
}

.parent-tab-pane h3 {
  margin: 18px 0 10px;
  font-size: 14px;
  color: #1d3557;
}
.parent-tab-pane h3:first-of-type { margin-top: 0; }

.parent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e6eef5;
}
.parent-table th, .parent-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #eef3f7;
}
.parent-table th {
  background: #f3f7fb;
  font-weight: 700;
  color: #457b9d;
  font-size: 12px;
}
.parent-table tr:last-child td { border-bottom: none; }

.parent-col-subject,
.parent-col-time {
  white-space: nowrap;
}
.parent-col-acc {
  white-space: nowrap;
  line-height: 1.25;
  vertical-align: middle;
}
th.parent-col-acc {
  white-space: normal;
}
.parent-col-acc .parent-bar {
  display: inline-block;
  width: 48px;
  margin: 0 0 0 6px;
  vertical-align: middle;
}
.parent-col-topic {
  word-break: break-word;
}

/* Phone portrait: overview + attempts */
@media (max-width: 700px) and (orientation: portrait) {
  .po-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .po-stat {
    padding: 10px 6px;
  }
  .po-stat span {
    font-size: 20px;
  }
  .po-skills {
    grid-template-columns: 1fr;
  }
  .po-subject-head,
  .po-topic-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  #parent-tab-attempts .parent-table th,
  #parent-tab-attempts .parent-table td {
    padding: 8px 6px;
    font-size: 12px;
  }
  #parent-tab-attempts .parent-table th {
    font-size: 11px;
  }
  .parent-col-acc {
    overflow: hidden;
  }
  .parent-col-acc .parent-bar {
    width: 26px;
    height: 6px;
    margin: 0 0 0 4px;
  }
}
#parent-tab-attempts .parent-table {
  table-layout: fixed;
  width: 100%;
}
.parent-table td.parent-q,
.parent-table th:nth-child(3) {
  width: 34%;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: top;
}
.parent-table td.parent-answer,
.parent-table th:nth-child(4) {
  width: 18%;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: top;
  color: #1d3557;
  font-weight: 600;
}
.parent-answer { color: #1d3557; font-weight: 600; }
.parent-media-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
}
.parent-thumb {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #dbe4ec;
  padding: 2px;
  flex-shrink: 0;
}
.parent-media-caption {
  font-size: 13px;
  line-height: 1.4;
  font-weight: inherit;
  color: inherit;
}
.parent-media-cell--answer .parent-media-caption {
  font-weight: 600;
}
.parent-ok { color: #2a9d8f; font-weight: 700; }
.parent-bad { color: #e63946; font-weight: 700; }
.parent-timeout { color: #f4a261; font-weight: 700; }
.parent-empty { text-align: center; color: #8aa0b4; padding: 24px; }

.parent-sort-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.parent-sort-btn:hover { color: #1d3557; }
.parent-sort-btn.active { color: #1d3557; }
.parent-sort-ind {
  font-size: 10px;
  min-width: 10px;
  color: #8aa0b4;
}
.parent-sort-btn.active .parent-sort-ind { color: #2ec4b6; }

.parent-bar {
  display: inline-block;
  width: 70px;
  height: 8px;
  background: #e6eef5;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
  overflow: hidden;
}
.parent-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2ec4b6, #52d273);
  border-radius: 999px;
}

.parent-field {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.parent-field span { font-size: 13px; color: #457b9d; min-width: 110px; }
.parent-field select, .parent-field input {
  padding: 8px 12px;
  border: 1px solid #d8e4ee;
  border-radius: 10px;
  font-size: 14px;
}
#parent-set-pin, #parent-clear-pin {
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  margin-right: 8px;
}
#parent-set-pin { background: #2ec4b6; color: #fff; }
#parent-clear-pin { background: #e6eef5; color: #457b9d; }
#parent-difficulty-msg, #parent-pin-set-msg, #parent-clear-msg { color: #2a9d8f; font-size: 12px; margin-top: 6px; }
.parent-note { font-size: 12px; color: #8aa0b4; margin-top: 10px; }
.parent-warn {
  font-size: 13px;
  color: #c1121f;
  background: #fff5f5;
  border: 1px solid #f5c2c7;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
  line-height: 1.5;
}
.parent-danger-btn {
  background: #e63946;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}
.parent-danger-btn:active { transform: scale(0.98); }

#parent-ai-prompt {
  background: #457b9d;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}

#parent-tab-settings #save-debug,
#parent-tab-settings .parent-debug {
  position: static;
  top: auto;
  right: auto;
  max-width: none;
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  justify-content: flex-start;
}
#parent-tab-settings .save-debug-link {
  color: #457b9d;
  text-shadow: none;
  font-size: 13px;
}
#parent-tab-settings .save-debug-link:hover { color: #1d3557; }
#parent-tab-settings .save-debug-link.danger { color: #e63946; }
#parent-tab-settings .save-debug-bytes {
  color: #2a9d8f;
  text-shadow: none;
  font-size: 13px;
}

#parent-ai-modal {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 16, 32, 0.55);
}
#parent-ai-modal.hidden { display: none; }
#parent-ai-card {
  width: min(720px, 96vw);
  max-height: min(88vh, 720px);
  background: #f8fbfd;
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 18px 18px;
}
#parent-ai-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
#parent-ai-head h3 {
  margin: 0;
  font-size: 16px;
  color: #1d3557;
}
#parent-ai-close {
  border: none;
  background: none;
  font-size: 20px;
  color: #8aa0b4;
  cursor: pointer;
}
#parent-ai-text {
  width: 100%;
  flex: 1;
  min-height: 240px;
  resize: vertical;
  border: 1px solid #d8e4ee;
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #1d3557;
  background: #fff;
  box-sizing: border-box;
}
#parent-ai-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
#parent-ai-copy {
  background: #2ec4b6;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}
#parent-ai-copy-msg { font-size: 13px; color: #2a9d8f; }

.parent-editor-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 10px;
  background: #1d3557;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

#parent-btn {
  display: block;
  margin-top: 0;
  background: none;
  border: 1px solid #d8e4ee;
  border-radius: 999px;
  padding: 8px 22px;
  color: #457b9d;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}
#parent-btn:hover { background: #f0f7f6; }

#game-exit-btn {
  background: rgba(20, 32, 48, 0.55);
  backdrop-filter: blur(6px);
  border: none;
  border-radius: 999px;
  width: 42px;
  height: 42px;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game-exit-btn:active { transform: scale(0.95); }
#game-exit-btn.hidden { display: none; }

/* ---------- Mobile: full-page parent zone (not a floating window) ---------- */
/* iPhone 16 Pro Max landscape ≈ 956px wide — must be above 950 */
@media (max-width: 1100px), (orientation: landscape) and (max-height: 540px) {
  #parent-overlay {
    align-items: stretch;
    justify-content: stretch;
    /* Edge-to-edge — no side gaps. Safe-area goes on content, not the page chrome. */
    inset: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: #f8fbfd;
  }

  #parent-card {
    width: 100%;
    max-width: none;
    max-height: none;
    height: 100%;
    min-height: 100%;
    border-radius: 0;
    box-shadow: none;
  }

  #parent-head {
    padding: 12px max(14px, env(safe-area-inset-right, 0px)) 12px max(14px, env(safe-area-inset-left, 0px));
    padding-top: max(12px, env(safe-area-inset-top, 0px));
  }

  #parent-tabs {
    gap: 4px;
    padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  }

  .parent-tab-pane {
    padding: 14px max(12px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }

  .po-stats {
    gap: 8px;
  }

  .po-stat {
    padding: 10px 6px;
  }

  .po-stat span {
    font-size: 20px;
  }

  #parent-pin-gate {
    padding: max(28px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) max(28px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  }
}

/* Phone landscape: tighter spacing on the same full-page layout */
@media ((max-width: 1100px) and (orientation: landscape)), (orientation: landscape) and (max-height: 540px) {
  #parent-overlay {
    padding: 0;
    background: #f8fbfd;
  }

  #parent-card {
    width: 100%;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
  }

  #parent-head {
    padding: 6px max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px));
    min-height: 36px;
  }
  #parent-head h2 {
    font-size: 15px;
  }
  #parent-close-panel {
    font-size: 18px;
    padding: 2px 6px;
  }

  #parent-tabs {
    gap: 4px;
    padding: 0 max(10px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px));
  }
  .parent-tab {
    padding: 6px 12px;
    font-size: 13px;
    border-bottom-width: 2px;
  }

  .parent-tab-pane {
    padding: 8px max(12px, env(safe-area-inset-right, 0px)) max(10px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }

  .po-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  .po-stat {
    border-radius: 10px;
    padding: 6px 4px;
  }
  .po-stat span {
    font-size: 16px;
    line-height: 1.15;
  }
  .po-stat label {
    font-size: 10px;
    margin-top: 2px;
  }

  .parent-tab-pane h3 {
    margin: 8px 0 4px;
    font-size: 12px;
  }
  .parent-tab-pane h3:first-of-type {
    margin-top: 0;
  }

  .parent-table {
    font-size: 12px;
    border-radius: 8px;
  }
  .parent-table th,
  .parent-table td {
    padding: 5px 8px;
    white-space: nowrap;
  }
  .parent-table th {
    font-size: 11px;
  }

  .parent-col-acc {
    white-space: nowrap;
  }
  th.parent-col-acc {
    white-space: normal;
  }
  .parent-col-acc .parent-bar {
    display: inline-block;
    width: 40px;
    height: 6px;
    margin: 0 0 0 4px;
    vertical-align: middle;
  }
  .parent-col-topic {
    white-space: normal;
  }
  .parent-table td.parent-q,
  .parent-table th:nth-child(3) {
    width: 36%;
    max-width: none;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .parent-table td.parent-answer,
  .parent-table th:nth-child(4) {
    width: 18%;
    max-width: none;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .parent-bar {
    width: 42px;
    height: 6px;
    margin-left: 4px;
  }
  .parent-empty {
    padding: 12px;
  }

  #parent-pin-gate {
    padding: 20px 16px;
  }
}

/* Very short landscape */
@media (orientation: landscape) and (max-height: 420px) {
  #parent-head {
    padding: 4px 10px;
  }
  .po-stats {
    gap: 4px;
  }
  .po-stat {
    padding: 4px 2px;
  }
  .po-stat span {
    font-size: 14px;
  }
  .po-stat label {
    font-size: 9px;
  }
  .parent-bar {
    display: none;
  }
  .parent-tab-pane {
    padding: 6px 10px 8px;
  }
}
