/*
 * The player's chrome: a host page around an activity. The activity is the subject; the header
 * says what is playing and under which session, the footer holds what only a host can do.
 *
 * One accent, reserved for the primary action and focus. Correct and wrong are their own family.
 * Typefaces come from dist/fonts.css, generated by tools/build-apps.mjs.
 */

:root {
  color-scheme: light;
  --ink: #131c26;
  --ink-2: #4a5b6d;
  --ink-3: #74838f;
  --page: #eef2f6;
  --surface: #ffffff;
  --sunken: #f5f8fb;
  --line: #d7dee6;
  --line-2: #b7c3cf;
  --accent: #15619f;
  --accent-ink: #0f4a7a;
  --accent-on: #ffffff;
  --accent-soft: #e2eef8;
  --good: #12693e;
  --good-soft: #e3f3ea;
  --warn: #8a5300;
  --bad: #a82f1c;
  --bad-soft: #fbe9e5;
  --shadow: 0 12px 32px rgba(19, 28, 38, 0.18);
  --sans: Rubik, 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #e4ebf2;
    --ink-2: #a3b2c1;
    --ink-3: #8696a6;
    --page: #0f161d;
    --surface: #18222c;
    --sunken: #141d26;
    --line: #2c3a47;
    --line-2: #3d4e5e;
    --accent: #6cb0ea;
    --accent-ink: #9ccaf2;
    --accent-on: #0f161d;
    --accent-soft: #1d3346;
    --good: #6fcf9b;
    --good-soft: #17352a;
    --warn: #e7b25c;
    --bad: #f08a76;
    --bad-soft: #3d1f1a;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.4 var(--sans);
}

h1,
h2,
p {
  margin: 0;
}

button,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------ header */

/*
 * Both bars float over the activity rather than squeezing it: the page scrolls, the asset is as tall
 * as it says it is, and the chrome stays put with the content visible through it.
 */
.top,
.controls {
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
}

.top {
  position: sticky;
  top: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}

.no-header .bar {
  display: none;
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-height: 64px;
  padding: 10px 24px;
}

.identity {
  flex: 1 1 280px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-on);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mark svg {
  width: 18px;
  height: 18px;
}

.titles {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.bar .title {
  min-width: 0;
  font-size: 18px;
}

.title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Asset titles are mostly Hebrew in an English chrome: each run keeps its direction, and the
     line still starts where the chrome's lines start. */
  unicode-bidi: plaintext;
  text-align: left;
}

.meta {
  font: 12px/1.4 var(--mono);
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link {
  border: 0;
  background: none;
  padding: 4px 6px;
  color: var(--accent);
  border-radius: 6px;
  white-space: nowrap;
}

.link:hover {
  text-decoration: underline;
}

.tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool.icon {
  width: 40px;
  padding: 0;
  justify-content: center;
}

.tool[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.count {
  font: 12px/1.6 var(--mono);
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.tool[aria-pressed='true'] .count {
  background: var(--surface);
}

/* ------------------------------------------------------------ stage */

/* Measured by the page (main.ts), so the content clears both bars whatever they wrap to. */
:root {
  --top-h: 69px;
  --foot-h: 72px;
  --trace-w: 380px;
}

.body {
  flex: 1;
}

/*
 * The activity gets the whole width and everything between the bars, as it would in a host page:
 * the asset owns its layout, so the player adds no card, margin or width cap of its own.
 */
.stage {
  display: flex;
  padding: 0 0 var(--foot-h);
}

.trace-open .stage {
  padding-inline-end: var(--trace-w);
}

.frame {
  width: 100%;
  display: flex;
}

/* As tall as the asset reports, and at least the room between the bars until it has. */
.frame iframe {
  flex: 1;
  width: 100%;
  min-height: calc(100vh - var(--top-h) - var(--foot-h));
  border: 0;
  background: #ffffff;
}

.stage:fullscreen {
  padding: 0;
  overflow: auto;
  background: var(--page);
}

.stage:fullscreen .frame {
  max-width: none;
  border-radius: 0;
  border: 0;
}

.problem {
  margin: 24px auto;
  align-self: flex-start;
  max-width: 60ch;
  padding: 16px 20px;
  border-radius: 10px;
  background: var(--bad-soft);
  color: var(--bad);
}

.picker {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.picker h2 {
  font-size: 22px;
  font-weight: 600;
}

.picker-lead {
  color: var(--ink-2);
}

.picker-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker-empty {
  padding: 24px;
  border: 1px dashed var(--line-2);
  border-radius: 10px;
  color: var(--ink-2);
  text-align: center;
}

/* ------------------------------------------------------------ events drawer */

.trace {
  position: fixed;
  top: var(--top-h);
  bottom: var(--foot-h);
  right: 0;
  z-index: 15;
  width: var(--trace-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
}

.trace-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.trace-head h2 {
  font-size: 15px;
  font-weight: 600;
}

.log {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  font: 12px/1.45 var(--mono);
}

.log li {
  display: grid;
  grid-template-columns: 88px 64px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}

.log time {
  color: var(--ink-3);
}

.log .dir {
  font-weight: 600;
  color: var(--ink-2);
}

.log .dir[data-dir='in'] {
  color: var(--accent);
}

.log .dir[data-dir='out'] {
  color: var(--warn);
}

.log .text {
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------ footer */

.controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 12px 24px;
  border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}

/*
 * The footer wears the widget kit's theme (D87), as it sits under the activity: purple accent,
 * pill buttons, round page arrows. Only the footer: the header and the drawer stay the player's.
 */
.controls {
  --accent: #5a55f5;
  --accent-ink: #3d36b8;
  --accent-on: #ffffff;
  --accent-soft: #f4f2ff;
  --line: #e8e5f8;
  --line-2: #dcd8f5;
  --ink: #1d1947;
  --ink-2: #4a4570;
  --good: #1b8a60;
  --good-soft: #effaf5;
  --bad: #a3168f;
  --bad-soft: #fdf1fb;
  color: var(--ink);
  border-top-color: #ece9fb;
}

@media (prefers-color-scheme: dark) {
  .controls {
    --accent: #a9a3f0;
    --accent-ink: #c9c4ff;
    --accent-on: #1d1947;
    --accent-soft: #2a2654;
    --line: #3a3560;
    --line-2: #4a4578;
    --ink: #ece9ff;
    --ink-2: #b9b3ee;
    --good: #6fcf9b;
    --good-soft: #17352a;
    --bad: #f0a6e6;
    --bad-soft: #3a1a36;
    border-top-color: #3a3560;
  }
}

.controls button:not(.round) {
  border-radius: 999px;
}

.controls .ghost:hover:not(:disabled),
.controls .secondary:hover:not(:disabled),
.controls .round:not(.primary-round):hover:not(:disabled) {
  background: var(--accent-soft);
}

.controls .finish:hover:not(:disabled),
.controls .primary-round:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 88%, #000);
}

.zone {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zone.middle {
  gap: 12px;
}

.zone.end {
  justify-content: flex-end;
  gap: 12px;
}

.controls button {
  height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.ghost {
  border: 0;
  background: transparent;
  color: var(--ink-2);
}

.secondary {
  border: 1px solid var(--line-2);
  background: var(--surface);
}

.primary-outline {
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
}

/* Page navigation (D65): previous, where you are, next. Round so it reads as movement, not action. */
.controls .round {
  width: 48px;
  height: 48px;
  padding: 0;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--surface);
}

.controls .primary-round {
  border: 0;
  background: var(--accent);
  color: var(--accent-on);
}

.controls .round svg {
  width: 18px;
  height: 18px;
}

.pager-where {
  min-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.page-label {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.page-label span {
  color: var(--ink-2);
  font-weight: 400;
}

.page-dots {
  display: flex;
  gap: 4px;
}

.page-dots span {
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  transition: width 0.2s;
}

.page-dots span[data-state='seen'] {
  background: var(--line-2);
}

.page-dots span[data-state='current'] {
  width: 18px;
  background: var(--accent);
}

.status {
  color: var(--ink-2);
}

.result {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--sunken);
  white-space: nowrap;
}

.result strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.result[data-outcome='passed'] {
  background: var(--good-soft);
  color: var(--good);
}

.result[data-outcome='failed'] {
  background: var(--bad-soft);
  color: var(--bad);
}

/* ------------------------------------------------------------ narrow */

@media (max-width: 860px) {
  .bar {
    padding: 8px 16px;
  }

  /* Two rows: what is playing, then the session and the tools on one line. */
  .identity {
    flex-basis: 100%;
  }

  .sc-chip {
    margin-inline-end: auto;
  }

  .sc-detail,
  .tool-label,
  #fullscreen {
    display: none;
  }

  .tool {
    padding: 0 10px;
  }

  .trace-open .stage {
    padding-inline-end: 0;
  }

  .trace {
    left: 0;
    width: auto;
    border-inline-start: 0;
  }

  .controls {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    padding: 10px 16px;
  }

  .zone.middle {
    grid-column: 1 / -1;
    grid-row: 1;
    justify-content: center;
    min-width: 0;
  }
}

/* ------------------------------------------------------------ account */

.avatar-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sunken);
  color: var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 600;
  font-size: 13px;
}

.avatar[data-named='true'] {
  background: var(--accent);
  color: var(--accent-on);
  box-shadow: none;
}

.avatar.lg {
  width: 44px;
  height: 44px;
  font-size: 16px;
}

.avatar-btn[aria-expanded='true'] .avatar {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

.account-pop {
  position: fixed;
  top: calc(var(--top-h) + 8px);
  right: 16px;
  z-index: 30;
  width: min(300px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.account-id {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-who {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.account-who strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
  text-align: left;
}

.account-who span {
  color: var(--ink-2);
  font-size: 13px;
}

.account-action {
  height: 40px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 600;
}

/* A version that is not what learners see — only on the admin player (D76): drafts expire, review
   is pending, unpublished is pulled. */
.badge {
  display: inline-block;
  vertical-align: middle;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--sunken);
  color: var(--ink-2);
  box-shadow: inset 0 0 0 1px var(--line);
  white-space: nowrap;
}

.badge[data-status='draft'] {
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  color: var(--warn);
  box-shadow: none;
}

/* ------------------------------------------------------------ drawer tabs and xAPI */

.tabs {
  display: flex;
  gap: 4px;
}

.tabs button {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tabs button[aria-selected='true'] {
  background: var(--ink);
  color: var(--surface);
  font-weight: 600;
}

.tabs button[aria-selected='true'] .count {
  background: var(--surface);
}

.xapi {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.xapi-lrs {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line);
}

.xapi-lrs[data-state='sent'] {
  color: var(--good);
}

.xapi-lrs[data-state='failed'] {
  color: var(--bad);
}

.xapi-log {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  font: 12px/1.45 var(--mono);
}

.xapi-log li {
  border-bottom: 1px solid var(--line);
}

.xapi-log summary {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  list-style: none;
}

.xapi-log summary::-webkit-details-marker {
  display: none;
}

.xapi-log summary:hover {
  background: var(--sunken);
}

.xapi-log .verb {
  font-weight: 600;
  color: var(--accent);
}

.xapi-log .what {
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}

.xapi-log .result {
  color: var(--ink-2);
}

.xapi-log pre {
  margin: 0;
  padding: 8px 16px 12px;
  overflow: auto;
  background: var(--sunken);
  font: 11px/1.45 var(--mono);
  white-space: pre;
}

.trace .log,
.trace .xapi {
  flex: 1;
  min-height: 0;
}

/* ------------------------------------------------------------ finish, and the confirm before it */

/* A provider's way to end the attempt ("סיימתי", "Check me"): the one primary action in its footer. */
.controls .finish,
.summary .finish,
.confirm .finish {
  border: 0;
  background: var(--accent);
  color: var(--accent-on);
  font-weight: 600;
}

.controls .finish {
  min-width: 132px;
  justify-content: center;
}

.confirm {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.confirm::backdrop {
  background: rgba(15, 22, 29, 0.35);
}

.confirm p {
  margin: 0 0 16px;
  font-size: 15px;
}

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

.confirm-actions button {
  height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  font: inherit;
}

.confirm-actions .secondary {
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
}

/* ------------------------------------------------------------ evaluation summary */

/* The page after "בדקו אותי": a centred column, the words and one button, as LO's focus summary. */
.summary {
  flex: 1;
  min-height: calc(100vh - var(--top-h) - var(--foot-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 16px;
  text-align: center;
}

.summary-title {
  max-width: 40rem;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.35;
}

.summary-body {
  max-width: 40rem;
  color: var(--ink-2);
  font-size: 1.05rem;
  white-space: pre-line;
}

.summary-answers {
  height: 44px;
  min-width: 160px;
  padding: 0 24px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
}
