:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --text: #18202a;
  --muted: #657384;
  --line: #d8dee6;
  --accent: #1267d6;
  --ok: #0f8f5f;
  --warn: #bf7a00;
  --error: #c93434;
  --shadow: 0 14px 40px rgba(17, 24, 39, 0.12);
  --player-width: 100%;
  --player-height: 100%;
  --frame-width: 100%;
  --frame-height: 100%;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

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

.app-shell {
  width: var(--player-width);
  height: var(--player-height);
  min-height: 100dvh;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

.player-header {
  flex: 0 0 auto;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

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

.brand-mark {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #18324d;
  color: #ffffff;
  font-weight: 800;
  line-height: 1;
}

.brand h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  flex: 0 1 auto;
  max-width: 52vw;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.status-pill span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill[data-state="idle"] {
  color: var(--muted);
}
.status-pill[data-state="loading"] {
  color: var(--warn);
}

.status-pill[data-state="active"] {
  color: var(--accent);
}

.status-pill[data-state="saved"] {
  color: var(--ok);
}

.status-pill[data-state="error"] {
  color: var(--error);
}

.player-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

#scormFrame {
  width: var(--frame-width);
  height: var(--frame-height);
  display: block;
  border: 0;
  background: #ffffff;
}

.loading-overlay,
.error-state {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.94);
  text-align: center;
}

.loading-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-overlay p,
.error-state p {
  max-width: 560px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #dce3eb;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.error-state {
  color: var(--error);
}

.error-state h2 {
  margin: 0;
  color: var(--error);
  font-size: 20px;
  line-height: 1.25;
}

.debug-panel {
  flex: 0 0 34%;
  min-height: 180px;
  /* max-height: 42vh; */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: #111827;
  color: #d7e1ee;
}

.debug-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

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

.debug-header button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  cursor: pointer;
}

.debug-header button:active {
  transform: translateY(1px);
}

#debugLog,
#debugResponse,
#debugCmi {
  min-height: 0;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

#debugLog {
  flex: 0 0 42%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

#debugResponse {
  flex: 0 0 32%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #bfe4ff;
}

#debugCmi {
  flex: 1 1 auto;
}

[hidden] {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  .player-header {
    min-height: 54px;
    padding: 8px 10px;
  }

  .brand-mark {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .status-pill {
    max-width: 48vw;
    min-height: 32px;
    padding: 6px 9px;
    font-size: 12px;
  }

  .debug-panel {
    flex-basis: 42%;
    max-height: 50vh;
  }
}

.app-shell.is-header-hidden .player-header {
  display: none;
}

.app-shell.theme-minimal .brand-mark,
.app-shell.theme-minimal .status-pill {
  display: none;
}

.app-shell.theme-minimal .player-header {
  min-height: 44px;
  padding: 6px 12px;
}

.app-shell.theme-compact .player-header {
  min-height: 46px;
  padding: 6px 10px;
}

.app-shell.theme-compact .brand-mark {
  flex-basis: 28px;
  width: 28px;
  height: 28px;
}

.app-shell.theme-compact .brand h1 {
  font-size: 15px;
}

.app-shell.theme-dark {
  --bg: #0f1720;
  --surface: #121c28;
  --surface-soft: #172435;
  --text: #eef5ff;
  --muted: #a9b7c8;
  --line: #27364a;
  --accent: #5da2ff;
  background: var(--bg);
}

.app-shell.theme-dark .player-stage,
.app-shell.theme-dark #scormFrame {
  background: #0b1119;
}
.home-state {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.96),
      rgba(241, 247, 253, 0.96)
    ),
    var(--bg);
}

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

.home-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #18324d;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
}

.home-panel h2 {
  margin: 16px 0 8px;
  color: var(--text);
  font-size: 26px;
  line-height: 1.2;
}

.home-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.home-form {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.home-form label {
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
}

.home-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.home-input-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 10px 12px;
  outline: 0;
}

.home-input-row input:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(18, 103, 214, 0.12);
}

.home-input-row button,
.retake-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 750;
}

.home-input-row button,
.retake-actions .retake-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.home-hint {
  margin-top: 12px !important;
  font-size: 13px !important;
}

.retake-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 24, 40, 0.48);
}

.retake-dialog {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 64px rgba(17, 24, 39, 0.28);
  padding: 24px;
}

.retake-dialog h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 22px;
  line-height: 1.25;
}

.retake-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.retake-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.app-shell.theme-dark .home-state {
  background: rgba(15, 23, 32, 0.96);
}

.app-shell.theme-dark .home-panel,
.app-shell.theme-dark .retake-dialog {
  background: var(--surface);
}

@media (max-width: 640px) {
  .home-panel {
    padding: 20px;
  }

  .home-input-row {
    grid-template-columns: 1fr;
  }

  .home-input-row button,
  .retake-actions button {
    width: 100%;
  }
}
