:root {
  color-scheme: light;
  --paper: #eef3f1;
  --scene: #ffffff;
  --ink: #172126;
  --ink-soft: #40525b;
  --console: #173b52;
  --console-deep: #102a3b;
  --console-muted: #d5e2e7;
  --rule: #8ea4ad;
  --signal: #f4c84a;
  --signal-ink: #172126;
  --focus: #ffe37a;
  --focus-halo: #102a3b;
  --font-body: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-utility: "Atkinson Hyperlegible", "Avenir Next", var(--font-body);
}

.rehab-site-shell {
  font-size: 18px;
}

.rehab-site-shell__brand strong {
  font-size: 18px;
  white-space: nowrap;
}

@media (min-width: 681px) {
  .rehab-site-shell__brand {
    flex-basis: 208px;
  }
}

@media (max-width: 680px) {
  .rehab-site-shell__brand {
    flex: 0 0 120px;
    min-width: 120px;
  }
}

.rehab-site-shell__brand-note,
.rehab-site-shell__route-code {
  font-size: 16px;
}

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

html {
  min-width: 320px;
  scroll-behavior: auto;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
summary,
a {
  font: inherit;
}

button,
summary {
  cursor: pointer;
}

a {
  color: inherit;
}

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

:is(a, button, summary):focus-visible {
  box-shadow: 0 0 0 2px var(--focus-halo);
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 8px;
  left: 8px;
  display: inline-flex;
  min-width: 48px;
  min-height: 48px;
  padding: 10px 16px;
  align-items: center;
  background: var(--signal);
  color: var(--signal-ink);
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-140%);
}

.skip-link:focus {
  transform: translateY(0);
}

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

main {
  min-height: calc(100svh - var(--rehab-site-shell-height, 52px));
}

.play-shell {
  min-height: calc(100svh - var(--rehab-site-shell-height, 52px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(352px, 27.8vw, 380px);
  background: var(--scene);
}

.scene-stage {
  min-width: 0;
  min-height: calc(100svh - var(--rehab-site-shell-height, 52px));
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  background: var(--scene);
  border-right: 1px solid var(--ink);
}

.scene-sheet {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--scene);
}

.scene-image {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: calc(100svh - var(--rehab-site-shell-height, 52px) - 16px);
  aspect-ratio: 1672 / 941;
  object-fit: contain;
}

.scene-open {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 48px;
  place-items: center;
  border: 0;
  background: var(--scene);
  color: var(--ink);
}

.scene-open:disabled {
  cursor: wait;
}

.scene-open:focus-visible {
  outline-offset: -5px;
}

.scene-open-label {
  position: static;
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border: 0;
  border-top: 1px solid var(--ink);
  background: var(--scene);
  color: var(--console);
  font-size: 16px;
  font-weight: 800;
}

.scene-open:disabled .scene-open-label {
  display: none;
}

.scene-sheet[data-image-state="loading"] .scene-image,
.scene-sheet[data-image-state="error"] .scene-image {
  opacity: 0;
}

.scene-status {
  position: absolute;
  z-index: 1;
  inset: 16px;
  display: grid;
  max-width: 46rem;
  margin: auto;
  place-content: center;
  text-align: center;
}

.scene-status[hidden] {
  display: none;
}

.scene-status strong {
  font-size: 20px;
}

.scene-status p {
  max-width: 36rem;
  margin: 10px auto 0;
}

.scene-status button {
  min-height: 48px;
  margin: 16px auto 0;
  padding: 8px 16px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--signal);
  color: var(--signal-ink);
  font-weight: 800;
}

.play-console {
  min-width: 0;
  min-height: calc(100svh - var(--rehab-site-shell-height, 52px));
  padding: clamp(22px, 2vw, 28px);
  display: flex;
  flex-direction: column;
  background: var(--console);
  color: var(--scene);
}

.console-main {
  margin: auto 0;
}

.mode-label {
  margin: 0 0 8px;
  color: var(--signal);
  font-family: var(--font-utility);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.round-instruction {
  margin: 0 0 8px;
  color: var(--console-muted);
  font-size: 18px;
  line-height: 1.45;
}

h1 {
  max-width: 8ch;
  margin: 0;
  color: var(--scene);
  font-size: clamp(40px, 4.2vw, 62px);
  font-weight: 800;
  line-height: 1.08;
}

.route-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: clamp(24px, 4vh, 36px);
}

.route-button {
  position: relative;
  min-width: 0;
  min-height: 60px;
  padding: 7px 4px;
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: transparent;
  color: var(--scene);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.25;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.route-button > span:not(.step-number) {
  white-space: nowrap;
  word-break: keep-all;
}

.step-number {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-family: var(--font-utility);
  font-size: 16px;
  line-height: 1;
}

.route-button:hover {
  border-color: var(--scene);
}

.route-button[aria-pressed="true"] {
  border: 3px solid var(--signal-ink);
  background: var(--signal);
  color: var(--signal-ink);
}

.workmat-output {
  min-height: 64px;
  margin-top: 14px;
  padding: 8px 0 8px 16px;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
  border-left: 4px solid var(--signal);
  color: var(--scene);
}

.step-phase {
  color: var(--console-muted);
  font-family: var(--font-utility);
  font-size: 18px;
  font-weight: 800;
}

.workmat-output strong {
  font-size: 18px;
  line-height: 1.45;
}

.primary-action {
  min-height: 56px;
  margin-top: 18px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 2px solid var(--signal);
  border-radius: 4px;
  background: var(--signal);
  color: var(--signal-ink);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.primary-action:hover {
  border-color: var(--scene);
  background: #ffda58;
}

.action-arrow {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.console-utility {
  margin-top: auto;
  padding-top: 12px;
}

.guide,
.after-session {
  border-top: 1px solid var(--rule);
}

summary,
.after-session {
  min-height: 48px;
}

summary {
  padding: 10px 2px;
  align-content: center;
  color: var(--console-muted);
  font-size: 18px;
  font-weight: 700;
}

summary::marker {
  color: var(--signal);
}

.guide-body {
  padding: 0 2px 16px;
}

.guide-body p {
  margin: 0;
  color: var(--console-muted);
  font-size: 18px;
  line-height: 1.6;
}

.guide-body p + p {
  margin-top: 10px;
}

.after-session {
  padding: 8px 2px;
  display: flex;
  align-items: center;
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
  gap: 0;
  color: var(--scene);
  font-size: 18px;
  text-decoration: none;
}

.after-session:focus-visible {
  outline-offset: -5px;
  box-shadow: none;
}

.after-session span {
  color: var(--console-muted);
}

.after-session strong {
  color: var(--scene);
}

.after-session:hover strong {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.scene-dialog {
  width: min(96vw, 1100px);
  max-width: none;
  height: min(92svh, 820px);
  max-height: none;
  padding: 0;
  border: 3px solid var(--ink);
  background: var(--scene);
  color: var(--ink);
  overflow: auto;
}

.scene-dialog::backdrop {
  background: rgba(16, 42, 59, 0.82);
}

.scene-dialog-bar {
  position: sticky;
  z-index: 2;
  top: 0;
  min-height: 56px;
  padding: 4px 8px 4px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--ink);
  background: var(--scene);
}

.scene-dialog-bar strong {
  font-size: 18px;
}

.scene-dialog-bar button {
  min-width: 72px;
  min-height: 48px;
  border: 2px solid var(--ink);
  background: var(--signal);
  color: var(--signal-ink);
  font-weight: 800;
}

.scene-dialog > img {
  display: block;
  width: max(100%, 960px);
  height: auto;
}

@media (max-width: 900px),
  (min-width: 901px) and (max-width: 1144px) and (max-aspect-ratio: 4 / 3) {
  .play-shell {
    min-height: calc(100svh - var(--rehab-site-shell-height, 52px));
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .scene-stage {
    min-height: 0;
    grid-template-rows: auto;
    border-right: 0;
    border-bottom: 1px solid var(--ink);
  }

  .scene-sheet {
    padding: 8px;
  }

  .scene-image {
    width: min(100%, 860px);
    max-height: none;
  }

  .play-console {
    min-height: 0;
    padding: 22px 20px 16px;
  }

  .console-main {
    margin: 0;
  }

  .mode-label {
    margin-bottom: 8px;
  }

  h1 {
    max-width: none;
    font-size: clamp(36px, 10vw, 44px);
  }

  .route-controls {
    margin-top: 20px;
  }

  .console-utility {
    padding-top: 16px;
  }
}

@media (max-width: 430px) {
  .route-button {
    min-height: 60px;
    padding-inline: 4px;
    font-size: 17px;
  }

  .scene-dialog {
    width: calc(100vw - 16px);
    height: calc(100svh - 16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

@media (forced-colors: active) {
  .play-console,
  .scene-stage,
  .scene-open,
  .scene-dialog,
  .scene-dialog-bar,
  .route-button,
  .primary-action,
  .workmat-output,
  .guide,
  .after-session {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
    forced-color-adjust: auto;
  }

  .route-button[aria-pressed="true"] {
    border-width: 3px;
  }
}
