*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f5f5f5;
  color: #333;
}

body {
  display: flex;
  flex-direction: column;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #e8e8e8;
  border-bottom: 1px solid #ccc;
  flex-shrink: 0;
}

#url-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: #333;
  outline: none;
}
#url-input:focus { border-color: #2a8bf2; box-shadow: 0 0 0 2px rgba(42,139,242,.25); }

button {
  padding: 6px 14px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: #333;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #eee; }
button:active { background: #ddd; }
button:disabled { opacity: .5; cursor: default; }

#open-btn { background: #2a8bf2; color: #fff; border-color: #2a8bf2; }
#open-btn:hover { background: #1a7ae2; }
#open-btn:active { background: #1570d8; }


.main-area {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.upload-dropzone {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(42, 139, 242, .10), transparent 55%),
    linear-gradient(180deg, #fdfdfd 0%, #f3f3f3 100%);
  border-right: 1px solid #d7d7d7;
  cursor: pointer;
}

.upload-dropzone.dragover {
  background:
    radial-gradient(circle at top, rgba(42, 139, 242, .18), transparent 55%),
    linear-gradient(180deg, #ffffff 0%, #edf5ff 100%);
}

.upload-dropzone-content {
  width: min(560px, 100%);
  padding: 48px 32px;
  display: grid;
  gap: 10px;
  text-align: center;
  border: 2px dashed #9bb9e8;
  border-radius: 18px;
  background: rgba(255, 255, 255, .82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}

.upload-dropzone-content strong {
  font-size: 26px;
  font-weight: 650;
  color: #234066;
}

.upload-dropzone-content span {
  font-size: 14px;
  color: #5d6f86;
}

#scorm-frame {
  flex: 1;
  border: none;
  min-width: 0;
  background: #fff;
}

/* Debug panel */
.debug-panel {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #ccc;
  background: #fafafa;
  transition: width .15s ease;
}
.debug-panel.collapsed {
  width: 36px;
}
.debug-panel.collapsed .debug-log,
.debug-panel.collapsed .debug-header span,
.debug-panel.collapsed #debug-clear {
  display: none;
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid #ccc;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  flex-shrink: 0;
}
.debug-controls {
  display: flex;
  gap: 4px;
}
.debug-btn {
  padding: 2px 6px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid #ccc;
  background: #eee;
  color: #555;
  cursor: pointer;
  line-height: 1.3;
}
.debug-btn:hover { background: #ddd; }
#debug-toggle {
  font-size: 14px;
  font-weight: bold;
  transition: transform .15s ease;
}
.debug-panel.collapsed #debug-toggle {
  transform: rotate(180deg);
}

.debug-log {
  flex: 1;
  overflow-y: auto;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 11px;
  line-height: 1.5;
  padding: 4px 0;
}

.debug-entry {
  padding: 2px 8px;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.debug-entry:hover {
  white-space: normal;
  word-break: break-all;
}
.debug-entry .de-time {
  color: #999;
  margin-right: 6px;
}
.debug-entry .de-method {
  font-weight: 600;
  margin-right: 4px;
}
.debug-entry .de-arrow {
  color: #999;
  margin: 0 4px;
}
.debug-entry .de-value {
  color: #555;
}

/* Call type colors */
.debug-entry.de-lifecycle .de-method { color: #8e44ad; }
.debug-entry.de-get .de-method { color: #2a8bf2; }
.debug-entry.de-set .de-method { color: #e67e22; }
.debug-entry.de-set .de-value { color: #c0392b; }
.debug-entry.de-error .de-method { color: #e74c3c; }
.debug-entry.de-commit .de-method { color: #27ae60; }
.debug-entry.de-trackr .de-method { color: #888; }
.debug-entry.de-trackr-error .de-method { color: #e74c3c; }
.debug-entry.de-trackr-error { background: rgba(231,76,60,.06); }

/* Troubleshooting panel */
.troubleshoot {
  flex-shrink: 0;
  border-top: 1px solid #ccc;
  background: #fffbe6;
  max-height: 50vh;
  overflow-y: auto;
}
.troubleshoot-inner {
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.6;
  max-width: 800px;
  margin: 0 auto;
}
.troubleshoot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.troubleshoot-step {
  margin: 12px 0;
}
.troubleshoot-step ul {
  margin: 4px 0 4px 20px;
}
.troubleshoot-cmd {
  background: #2a2a2a;
  color: #e0e0e0;
  padding: 8px 10px;
  border-radius: 4px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 6px 0;
  cursor: pointer;
  position: relative;
}
.troubleshoot-cmd:hover::after {
  content: "click to copy";
  position: absolute;
  right: 8px;
  top: 8px;
  font-size: 10px;
  color: #888;
}
.troubleshoot code {
  background: #e8e8e8;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12px;
}

#new-window-label {
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

#preferred-language-select {
  padding: 6px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: #333;
}

.config-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, .28);
  z-index: 20;
}

.config-modal-panel {
  width: min(720px, 100%);
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  background: #f7f7f7;
  border: 1px solid #c9c9c9;
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .18);
  overflow: hidden;
}

.config-modal-header,
.config-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #ececec;
  border-bottom: 1px solid #d6d6d6;
}

.config-modal-footer {
  justify-content: flex-end;
  border-top: 1px solid #d6d6d6;
  border-bottom: none;
}

.config-modal-body {
  padding: 16px;
  overflow-y: auto;
}

.config-modal-body p {
  margin-bottom: 12px;
  font-size: 13px;
  color: #555;
}

.config-fields {
  display: grid;
  gap: 10px;
}

.config-row {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
}

.config-row label {
  font-size: 13px;
  font-weight: 600;
  color: #444;
}

.config-row input,
.config-row select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: #333;
}

.config-row-keys {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 11px;
  color: #777;
}

.footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 4px 12px;
  font-size: 11px;
  border-top: 1px solid #ccc;
  background: #e8e8e8;
}

#status {
  font-size: 13px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 240px;
}

#preferred-language {
  color: #666;
  overflow-wrap: anywhere;
}
.footer a {
  color: #666;
  text-decoration: none;
}
.footer a:hover {
  color: #2a8bf2;
  text-decoration: underline;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  html, body { background: #1e1e1e; color: #ddd; }
  .toolbar { background: #2a2a2a; border-color: #444; }
  #url-input { background: #333; color: #eee; border-color: #555; }
  #url-input:focus { border-color: #2a8bf2; }
  button { background: #333; color: #eee; border-color: #555; }
  button:hover { background: #3a3a3a; }
  button:active { background: #444; }
  #open-btn { background: #2a8bf2; color: #fff; border-color: #2a8bf2; }
  #status { color: #999; }
  .upload-dropzone {
    background:
      radial-gradient(circle at top, rgba(42, 139, 242, .16), transparent 55%),
      linear-gradient(180deg, #23272c 0%, #1d2024 100%);
    border-color: #444;
  }
  .upload-dropzone.dragover {
    background:
      radial-gradient(circle at top, rgba(42, 139, 242, .24), transparent 55%),
      linear-gradient(180deg, #242c38 0%, #1d2024 100%);
  }
  .upload-dropzone-content {
    background: rgba(34, 39, 46, .88);
    border-color: #5675a5;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
  }
  .upload-dropzone-content strong { color: #d8e7ff; }
  .upload-dropzone-content span { color: #9eb1cb; }
  #scorm-frame { background: #1e1e1e; }
  .footer { background: #2a2a2a; border-color: #444; }
  .footer a { color: #888; }
  .footer a:hover { color: #2a8bf2; }
  #status { color: #999; }
  #preferred-language { color: #999; }
  #new-window-label { color: #ddd; }
  #preferred-language-select { background: #333; color: #eee; border-color: #555; }

  .debug-panel { background: #252525; border-color: #444; }
  .debug-header { border-color: #444; color: #aaa; }
  .debug-btn { background: #333; border-color: #555; color: #aaa; }
  .debug-btn:hover { background: #3a3a3a; }
  .debug-entry { border-color: #333; }
  .debug-entry .de-time { color: #666; }
  .debug-entry .de-value { color: #aaa; }
  .debug-entry.de-set .de-value { color: #e74c3c; }
  .troubleshoot { background: #332d1a; border-color: #444; }
  .troubleshoot code { background: #444; color: #ddd; }
}

/* Standalone offline demo */
.demo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: #17314c;
  color: #fff;
}
.demo-header nav { display: inline-flex; gap: 14px; margin-left: 20px; }
.demo-header a { color: #c8e6ff; text-decoration: none; }
.demo-header a[aria-current="page"] { color: #fff; text-decoration: underline; }
.demo-header label { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.demo-header input { min-width: 0; max-width: 180px; padding: 7px 9px; border: 1px solid #9bb9d3; border-radius: 6px; font: inherit; }
.demo-courses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 12px; background: #edf3f9; }
.demo-card, .history-card { padding: 12px 14px; background: #fff; border: 1px solid #cedbe8; border-radius: 10px; }
.demo-card h2, .history-card h2 { font-size: 17px; color: #17314c; margin-bottom: 5px; }
.demo-card p, .history-card p { font-size: 14px; margin-bottom: 8px; line-height: 1.35; }
.demo-card .package-state { font-weight: 600; }
.demo-card button[data-action="download"] { background: #1675cd; border-color: #1675cd; color: #fff; }
.advanced-tools { background: #e8e8e8; }
.advanced-tools summary { padding: 5px 12px; cursor: pointer; font-size: 12px; }
.advanced-tools .toolbar { flex-wrap: wrap; }
.main-area { min-height: 280px; }
.history-page { min-height: 100%; height: auto; }
.history-main { width: min(900px, 100%); margin: 0 auto; padding: 24px 16px 50px; }
.history-main h1 { margin-bottom: 8px; }
.history-main > p { line-height: 1.4; margin-bottom: 20px; }
#download-status:empty { display: none; }
#download-status:not(:empty) { padding: 10px 12px; border: 1px solid #9bb9d3; border-radius: 8px; background: #e7f2ff; }
.history-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 24px; }
.history-events { list-style: none; display: grid; gap: 8px; }
.history-events li { display: grid; gap: 4px; padding: 12px 14px; background: #fff; border: 1px solid #d9e3ec; border-radius: 8px; }
.history-events span { color: #5d6975; font-size: 13px; }
.history-events p { font-size: 13px; overflow-wrap: anywhere; }
.history-main > h2 { margin: 20px 0 10px; }
.admin-section { margin-bottom: 16px; }
.admin-section button { background: #1675cd; border-color: #1675cd; color: #fff; }
.admin-section p { margin: 10px 0; }
.admin-section dl { display: grid; grid-template-columns: minmax(130px, 1fr) 1fr; gap: 8px 16px; margin-top: 12px; }
.admin-section dt { font-weight: 600; }
.admin-section dd { margin: 0; }
.name-gate[hidden] { display: none; }
.name-gate { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; background: rgba(9, 26, 44, .75); padding: 20px; }
.name-gate-panel { display: grid; gap: 14px; width: min(420px, 100%); padding: 24px; border-radius: 12px; background: #fff; color: #17314c; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.name-gate-panel p { line-height: 1.4; }
.name-gate-panel label { display: grid; gap: 6px; }
.name-gate-panel input { padding: 10px; font: inherit; border: 1px solid #9bb9d3; border-radius: 6px; }
.name-gate-panel button { background: #1675cd; border-color: #1675cd; color: #fff; }
@media (max-width: 700px) {
  html, body { height: auto; min-height: 100%; }
  .demo-header { flex-wrap: wrap; padding: 10px 12px; }
  .demo-header nav { margin-left: 10px; }
  .demo-header label { width: 100%; }
  .demo-header input { flex: 1; max-width: none; }
  .demo-courses, .history-summary { grid-template-columns: 1fr; }
  .main-area { min-height: 460px; height: 60vh; }
  .debug-panel { width: 36px; }
  .debug-panel .debug-log, .debug-panel .debug-header span, .debug-panel #debug-clear { display: none; }
  .debug-panel:not(.collapsed) { width: min(70vw, 300px); }
  .debug-panel:not(.collapsed) .debug-log, .debug-panel:not(.collapsed) .debug-header span,
  .debug-panel:not(.collapsed) #debug-clear { display: block; }
  .footer { flex-wrap: wrap; }
}
