/* ==========================================================================
   Layout - the workstation shell: navigation rail, command bar, workspace.
   Level 0 is the canvas the rail sits on; level 1 is the inset workspace.
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 100vh;
  background: var(--c-canvas);
}

/* ==========================================================================
   Navigation rail
   ========================================================================== */
.rail {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  height: 100vh;
  padding: 14px 10px 14px 12px;
  background: var(--c-rail);
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 4px 6px 4px 4px;
  border-radius: var(--r-lg);
  color: inherit;
  text-decoration: none;
  transition: background-color var(--dur-1) var(--ease-out);
}

/* The brand is the home link. */
a.brand:hover {
  background: rgba(14, 18, 27, 0.045);
  color: inherit;
}

a.brand:focus-visible {
  outline-offset: 0;
}

/*
 * The institutional crest is a detailed circular emblem: the gold lettering
 * around the ring is unreadable below about 36 CSS pixels, so the mark is sized
 * for legibility rather than for a tidy tile.
 */
.brand__mark {
  flex: none;
  display: block;
  width: 40px;
  height: 40px;
}

.brand__mark img {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 1px rgba(14, 18, 27, 0.18));
}

.brand__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand__name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  color: var(--c-ink-900);
  line-height: 1.15;
  white-space: nowrap;
}

.brand__sub {
  font-size: var(--fs-3xs);
  font-weight: var(--fw-medium);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-ink-400);
  line-height: 1.2;
  white-space: nowrap;
}

.rail__label {
  padding: 0 10px 6px;
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-ink-400);
}

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

.stages {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stages > li {
  position: relative;
}

.stage-sep {
  display: none;
}

.stage-step {
  position: relative;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 30px;
  padding: 0 8px 0 10px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--c-ink-600);
  text-align: left;
  white-space: nowrap;
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out);
}

.stage-step:disabled {
  cursor: default;
  color: var(--c-ink-400);
}

.stage-step:not(:disabled):hover {
  background: rgba(14, 18, 27, 0.045);
  color: var(--c-ink-900);
}

.stage-step:focus-visible {
  outline-offset: 0;
}

.stage-step__icon {
  display: inline-flex;
  color: var(--c-ink-400);
  transition: color var(--dur-1) var(--ease-out);
}

.stage-step__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The status glyph on the right: a number while pending, a tick when done. */
.stage-step__num {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 9.5px;
  font-weight: var(--fw-semibold);
  font-feature-settings: var(--num);
  color: var(--c-ink-400);
  box-shadow: inset 0 0 0 1px var(--c-ink-200);
  transition: background-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}

.stage-step__num svg {
  width: 9px;
  height: 9px;
}

.stage-step[data-state="done"] {
  color: var(--c-ink-700);
}

.stage-step[data-state="done"] .stage-step__num {
  background: var(--c-ink-800);
  box-shadow: none;
  color: var(--c-white);
}

.stage-step[data-state="done"] .stage-step__icon {
  color: var(--c-ink-500);
}

.stage-step[data-state="active"] {
  color: var(--c-ink-900);
  font-weight: var(--fw-semibold);
}

.stage-step[data-state="active"] .stage-step__icon {
  color: var(--c-blue);
}

.stage-step[data-state="active"] .stage-step__num {
  color: var(--c-blue);
  box-shadow: inset 0 0 0 1.5px var(--c-blue);
}

/* The current page is the one raised onto the workspace plane. */
.stage-step[aria-current="step"] {
  background: var(--c-surface);
  box-shadow: 0 0 0 1px var(--c-line), 0 1px 2px rgba(14, 18, 27, 0.06);
}

.stage-step[aria-current="step"]::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 0 2px 2px 0;
  background: var(--c-blue);
}

/* Progress: a hairline meter under the steps. */
.stagebar__rail {
  position: relative;
  height: 2px;
  margin: var(--sp-4) 10px 0;
  border-radius: 2px;
  background: var(--c-ink-150);
  overflow: hidden;
}

.stagebar__fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--c-ink-800);
  transition: width var(--dur-4) var(--ease-out);
}

.rail__foot {
  margin-top: auto;
  padding: 0 10px;
}

.rail__privacy {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: var(--fs-2xs);
  color: var(--c-ink-400);
  line-height: var(--lh-snug);
}

.rail__privacy svg {
  flex: none;
  margin-top: 1px;
}

/* ==========================================================================
   Frame: the workspace plane
   ========================================================================== */
.frame {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: calc(100vh - 16px);
  margin: 8px 8px 8px 0;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--r-2xl);
  box-shadow: 0 1px 2px rgba(14, 18, 27, 0.04), 0 8px 24px -16px rgba(14, 18, 27, 0.12);
}

/* --- Command bar ---------------------------------------------------------- */
.commandbar {
  position: sticky;
  top: 0;
  z-index: calc(var(--z-sticky) - 1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  height: var(--bar-h);
  padding: 0 var(--sp-4) 0 var(--sp-8);
  border-bottom: 1px solid var(--c-line-soft);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  background: color-mix(in srgb, var(--c-surface) 96%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
}

.commandbar__context {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
  font-size: var(--fs-sm);
}

.commandbar__empty {
  color: var(--c-ink-400);
}

.context-chip {
  display: none;
  align-items: baseline;
  gap: var(--sp-2);
  min-width: 0;
}

.context-chip[data-visible="true"] {
  display: flex;
}

.context-chip__dot {
  align-self: center;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--c-blue);
  flex: none;
}

.context-chip__course {
  flex: none;
  font-weight: var(--fw-semibold);
  color: var(--c-ink-900);
  letter-spacing: -0.005em;
}

.context-chip__meta {
  color: var(--c-ink-500);
  font-feature-settings: var(--num);
  white-space: nowrap;
}

.commandbar__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-left: var(--sp-3);
  border-left: 1px solid var(--c-line);
  font-size: var(--fs-xs);
  color: var(--c-ink-500);
  white-space: nowrap;
  font-feature-settings: var(--num);
}

.commandbar__status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-success);
}

.commandbar__status[data-tone="demo"]::before {
  background: var(--c-accent);
}

.commandbar__status[data-tone="final"] {
  color: var(--c-success);
  font-weight: var(--fw-medium);
}

.app-header__tools {
  display: flex;
  align-items: center;
  height: 100%;
  min-width: 0;
}

.app-header__tools > * + * {
  margin-left: var(--sp-2);
  padding-left: var(--sp-3);
  border-left: 1px solid var(--c-line);
}

.session-action {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex: none;
  flex-wrap: wrap;
}

/* Instructor: a labelled inline field, not a pill. */
.session-field {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 30px;
  min-width: 0;
}

.session-field__label {
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  color: var(--c-ink-400);
  white-space: nowrap;
}

.session-field__input {
  width: 168px;
  min-width: 0;
  height: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--c-ink-900);
  text-overflow: ellipsis;
  transition: border-color var(--dur-1) var(--ease-out), background-color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out);
}

.session-field__input:hover {
  background: var(--c-surface-3);
}

.session-field__input:focus {
  outline: none;
  background: var(--c-surface);
  border-color: var(--c-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-focus) 16%, transparent);
}

.session-field__input::placeholder {
  color: var(--c-ink-400);
  font-weight: var(--fw-regular);
}

.session-field[data-invalid="true"] .session-field__input {
  border-color: var(--c-warning-line);
  background: var(--c-warning-soft);
}

.session-field[data-invalid="true"] .session-field__label {
  color: var(--c-warning);
}

/* --- Timer ---------------------------------------------------------------- */
.timer {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-sm);
}

.timer__dial {
  width: 14px;
  height: 14px;
  flex: none;
}

.timer__dial svg {
  width: 14px;
  height: 14px;
  transform: rotate(-90deg);
}

.timer__track {
  fill: none;
  stroke: var(--c-ink-150);
  stroke-width: 3.5;
}

.timer__arc {
  fill: none;
  stroke: var(--c-accent);
  stroke-width: 3.5;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-4) var(--ease-out);
}

.timer__value {
  min-width: 36px;
  font-weight: var(--fw-semibold);
  font-feature-settings: var(--num);
  color: var(--c-ink-900);
}

.timer__state {
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-ink-400);
}

.timer[data-state="running"] .timer__state {
  color: var(--c-accent);
}

.timer[data-state="paused"] .timer__state {
  color: var(--c-warning);
}

.timer[data-state="stopped"] .timer__state {
  color: var(--c-success);
}

.timer[data-state="stopped"] .timer__arc {
  stroke: var(--c-success);
}

/* ==========================================================================
   Main and page headers
   ========================================================================== */
.main {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--shell-max);
  padding: var(--sp-7) var(--sp-8) var(--sp-12);
}

.main:focus {
  outline: none;
}

.stage {
  display: none;
  /* backwards, not both: a retained transform would make the stage the
     containing block for fixed children such as the phone action bar. */
  animation: stage-in var(--dur-3) var(--ease-out) backwards;
}

.stage[data-active="true"] {
  display: block;
}

@keyframes stage-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.stage__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4) var(--sp-6);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.stage__head > div:first-child {
  min-width: 0;
}

.stage__eyebrow {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--sp-2);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-ink-400);
  white-space: pre-wrap;
}

.stage__context {
  color: var(--c-ink-600);
}

.stage__title {
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.028em;
  line-height: 1.15;
  color: var(--c-ink-900);
}

.stage__desc {
  margin-top: 6px;
  font-size: var(--fs-sm);
  color: var(--c-ink-500);
  max-width: 76ch;
  line-height: var(--lh-snug);
}

.stage__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

/* --- Section typography shared by every workspace ---------------------- */
.section-title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--c-ink-900);
  letter-spacing: -0.005em;
  line-height: 1.3;
}

.section-hint {
  margin-top: 2px;
  font-size: var(--fs-xs);
  color: var(--c-ink-500);
  line-height: var(--lh-snug);
}

/* --- Grids -------------------------------------------------------------- */
.grid {
  display: grid;
  gap: var(--sp-4);
}

.grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.stack--sm {
  gap: var(--sp-2);
}

.cluster {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

/* --- Footer ------------------------------------------------------------- */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-2) var(--sp-8);
  flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-8);
  border-top: 1px solid var(--c-line-soft);
  font-size: var(--fs-2xs);
  color: var(--c-ink-400);
}

.app-footer p {
  max-width: 80ch;
}

.app-footer b {
  font-weight: var(--fw-semibold);
  color: var(--c-ink-600);
}

.footer-links {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2) var(--sp-4);
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--c-ink-500);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--c-ink-900);
  text-decoration: underline;
}

/* ==========================================================================
   Responsive shell
   ========================================================================== */

/* Tablet: the rail folds to icons; labels move into tooltips. */
@media (max-width: 1100px) {
  .app {
    grid-template-columns: var(--rail-w-compact) minmax(0, 1fr);
  }

  .rail {
    align-items: center;
    padding-inline: 8px;
  }

  .brand {
    padding: 2px 0 0;
  }

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

  .stagebar,
  .stages {
    width: 100%;
    align-items: center;
  }

  .stage-step {
    display: grid;
    place-items: center;
    grid-template-columns: 1fr;
    width: 40px;
    height: 36px;
    padding: 0;
  }

  .stage-step__num {
    position: absolute;
    right: 1px;
    top: 1px;
    width: 13px;
    height: 13px;
    font-size: 8px;
  }

  .stage-step[data-state="pending"] .stage-step__num {
    display: none;
  }

  .stage-step[aria-current="step"]::before {
    left: -8px;
  }

  .stagebar__rail {
    width: 28px;
    margin-inline: auto;
  }

  .rail__foot {
    display: none;
  }

  .main {
    padding-inline: var(--sp-6);
  }

  .commandbar {
    padding-left: var(--sp-6);
  }

  .app-footer {
    padding-inline: var(--sp-6);
  }
}

@media (max-width: 900px) {
  .session-field__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .session-field__input {
    width: 140px;
  }
}

/* Phone: the rail becomes a compact top bar; the workspace goes edge to edge. */
@media (max-width: 720px) {
  .app {
    display: block;
  }

  .rail {
    position: sticky;
    top: 0;
    flex-direction: row;
    align-items: center;
    gap: var(--sp-3);
    height: 56px;
    padding: 0 var(--sp-3);
    border-bottom: 1px solid var(--c-line);
    background: color-mix(in srgb, var(--c-rail) 97%, transparent);
    backdrop-filter: saturate(160%) blur(10px);
    -webkit-backdrop-filter: saturate(160%) blur(10px);
  }

  .brand {
    flex: none;
  }

  .stagebar {
    flex: 1 1 auto;
    flex-direction: row;
    align-items: center;
    width: auto;
    min-width: 0;
  }

  .stages {
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
    gap: 0;
  }

  .stage-step {
    width: 36px;
    height: 36px;
  }

  .stage-step[aria-current="step"]::before {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: -10px;
    width: auto;
    height: 2px;
    border-radius: 2px 2px 0 0;
  }

  .stagebar__rail {
    display: none;
  }

  .frame {
    margin: 0;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .commandbar {
    position: static;
    height: auto;
    min-height: 44px;
    flex-wrap: wrap;
    row-gap: 4px;
    padding: 6px var(--sp-4);
    border-radius: 0;
    background: var(--c-surface);
  }

  .session-field__input {
    width: 130px;
  }

  .timer__state {
    display: none;
  }

  .main {
    padding: var(--sp-5) var(--sp-4) var(--sp-10);
  }

  .stage__head {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
  }

  .stage__title {
    font-size: 1.375rem;
  }

  .stage__actions {
    width: 100%;
  }

  .app-footer {
    flex-direction: column;
    padding: var(--sp-4);
  }

  html {
    scroll-padding-top: 64px;
  }
}

@media (max-width: 380px) {
  .commandbar__status {
    display: none;
  }

  .session-field__label {
    display: none;
  }
}
