:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1d2430;
  --muted: #687385;
  --line: #d5dce5;
  --accent: #1f6f78;
  --accent-soft: #e7f3f5;
  --accent-ink: #ffffff;
  --focus: #0b57d0;
  --header: #17212b;
  --header-ink: #ffffff;
  --toolbar: rgba(255, 255, 255, 0.92);
  --shadow: 0 18px 40px rgba(29, 36, 48, 0.12);
  --editor-size: 22px;
  --editor-line: 1.6;
  font-family: Inter, "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--header);
  color: var(--header-ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08) inset;
}

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

.identity::before {
  content: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: block;
  background: url("icon.svg?v=0.1") center / contain no-repeat;
}

.identity strong {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.identity span {
  color: var(--header-ink);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.clock-display {
  min-height: 28px;
  min-width: 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.78) !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
}

.clock-display[hidden] {
  display: inline-flex !important;
  visibility: hidden;
}

.status-line {
  color: rgba(255, 255, 255, 0.78);
  font-size: 15px;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  white-space: nowrap;
}

#saveStatus.unsaved {
  color: #ff5c5c;
  font-weight: 800;
}

#saveStatus {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

#saveStatus.unsaved {
  background: rgba(255, 92, 92, 0.14);
}

.last-saved {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--toolbar);
  backdrop-filter: blur(10px);
  box-shadow: 0 1px 8px rgba(29, 36, 48, 0.06);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  background: #f8fafc;
}

.toolbar-end {
  margin-left: auto;
}

button,
.select-control {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
}

button {
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, color 120ms ease;
}

button:hover {
  background: #ffffff;
  border-color: #cbd5df;
  box-shadow: 0 1px 3px rgba(29, 36, 48, 0.08);
}

button:hover,
button:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button:active,
button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.pause-button,
.details-button,
.finish-button {
  min-height: 32px;
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: var(--header-ink);
  font-size: 14px;
}

.pause-button:hover,
.details-button:hover,
.finish-button:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.42);
}

.view-menu {
  position: absolute;
  top: 10px;
  right: 20px;
  z-index: 5;
  width: min(720px, calc(100vw - 40px));
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid #cbd5df;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 34px rgba(31, 41, 51, 0.18);
}

.view-menu button,
.view-menu .select-control {
  width: 100%;
  justify-content: center;
  border-color: #cbd5df;
  background: #f8fafc;
  box-shadow: 0 1px 2px rgba(29, 36, 48, 0.06);
}

.view-menu button:hover,
.view-menu .select-control:hover {
  background: #ffffff;
  border-color: #9fb0c2;
}

.view-menu button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 6px rgba(31, 111, 120, 0.24);
}

.view-menu[hidden],
.sr-only[hidden] {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.select-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-color: #d8e0e8;
  background: #ffffff;
}

.select-control span {
  color: var(--muted);
  font-size: 14px;
}

select {
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.notice {
  padding: 10px 18px;
  background: #fff4ce;
  border-bottom: 1px solid #e2ca7b;
  color: #4c3b00;
}

.editor-wrap {
  min-height: calc(100vh - 210px);
  padding: 24px clamp(16px, 5vw, 84px) 12px;
  display: flex;
  justify-content: center;
  align-items: stretch;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(244, 246, 248, 0)),
    var(--bg);
}

.editor-surface {
  width: 100%;
  max-width: 1144px;
  min-height: calc(100vh - 250px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 14px;
  gap: 10px;
}

#editor {
  width: 100%;
  max-width: none;
  height: 100%;
  min-height: calc(100vh - 250px);
  resize: none;
  overflow-y: scroll;
  scrollbar-color: #8fa2b5 #edf1f4;
  scrollbar-width: auto;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  padding: clamp(22px, 4vw, 46px);
  background: var(--panel);
  color: var(--ink);
  font-size: var(--editor-size);
  line-height: var(--editor-line);
  box-shadow: var(--shadow);
  caret-color: var(--accent);
}

.document-position {
  min-height: 100%;
  display: flex;
  justify-content: center;
  padding: 12px 0;
}

.document-position-track {
  position: relative;
  width: 6px;
  height: 100%;
  min-height: 120px;
  border-radius: 999px;
  background: #dce4eb;
  box-shadow: inset 0 0 0 1px #cbd5df;
}

.document-position-thumb {
  position: absolute;
  left: -2px;
  width: 10px;
  min-height: 22px;
  border-radius: 999px;
  background: #6f879d;
  box-shadow: 0 1px 2px rgba(29, 36, 48, 0.2);
}

.document-position-caret {
  position: absolute;
  left: -4px;
  width: 14px;
  height: 4px;
  border-radius: 999px;
  background: #f4c542;
  box-shadow: 0 0 0 1px rgba(23, 33, 43, 0.36);
}

#editor::placeholder {
  color: #8a94a6;
}

.word-panel {
  display: flex;
  gap: 18px;
  justify-content: flex-end;
  align-items: center;
  align-self: start;
  width: min(1120px, calc(100% - 32px));
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 clamp(16px, 5vw, 84px) 16px;
  color: var(--muted);
  font-size: 15px;
}

.word-panel span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 8px 11px;
  border: 1px solid #d8e0e8;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 1px 3px rgba(29, 36, 48, 0.06);
  align-self: center;
  min-height: 0;
  height: auto;
}

.word-panel strong {
  color: var(--ink);
}

.word-panel[hidden] {
  display: none !important;
}

.print-output {
  display: none;
}

.print-pages {
  display: grid;
  gap: 18px;
}

.print-page {
  position: relative;
  min-height: 720px;
  padding: 30px 0 0;
}

.print-page-body {
  white-space: pre-wrap;
}

.print-page-header {
  position: absolute;
  left: 0;
  top: 0;
  color: #4f5b6a;
  font-size: 13px;
}

.setup-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(18, 25, 33, 0.62);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.setup-overlay[hidden] {
  display: none;
}

.setup-panel {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  position: relative;
  overflow: hidden;
}

.setup-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--accent);
}

.setup-panel h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.setup-subtitle {
  margin: -12px 0 4px;
  color: var(--muted);
  font-size: 17px;
  font-weight: 700;
}

.autosave-panel p:not(.setup-notice) {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.navigation-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.finish-panel {
  width: min(560px, 100%);
}

.finish-checklist {
  display: grid;
  gap: 16px;
}

.finish-panel.is-complete {
  min-height: 260px;
  place-content: center;
  text-align: center;
}

.finish-panel.is-complete h1 {
  margin: 0;
  color: var(--muted);
  font-size: 19px;
}

.finish-panel.is-complete .setup-notice {
  width: min(100%, 360px);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  justify-self: center;
  font-size: 25px;
  line-height: 1.35;
}

.finish-intro {
  margin: 0;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: #eef6f7;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.4;
}

.finish-check {
  display: grid !important;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: flex-start;
  gap: 10px;
  font-weight: 600 !important;
  line-height: 1.35;
}

.finish-check input[type="checkbox"] {
  box-sizing: border-box;
  width: 20px;
  min-width: 20px;
  height: 20px;
  min-height: 20px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.finish-panel button:disabled {
  cursor: not-allowed;
  border-color: #cbd5df;
  background: #dfe5ea;
  color: #6b7785;
}

#completeSessionButton:not(:disabled) {
  border-color: #c2484e;
  background: #c2484e;
  color: #ffffff;
}

#completeSessionButton:not(:disabled):hover {
  border-color: #a9363c;
  background: #a9363c;
}

.single-action {
  grid-template-columns: 1fr;
}

.setup-panel label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.setup-panel input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cbd5df;
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
}

.setup-panel input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.setup-panel input[readonly] {
  background: #eef1f3;
  color: var(--muted);
}

.setup-notice {
  margin: -2px 0 0;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: #eef6f7;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.35;
  white-space: pre-line;
}

.setup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.setup-launch-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.setup-identity-fields {
  display: grid;
  gap: 16px;
}

.setup-panel button {
  min-height: 44px;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  border-radius: 6px;
}

.setup-panel .secondary-button {
  background: #ffffff;
  border-color: #aeb9c2;
  color: var(--ink);
}

.setup-panel .secondary-button[hidden] + button {
  grid-column: 1 / -1;
}

body.high-contrast {
  --bg: #000000;
  --panel: #000000;
  --ink: #ffffff;
  --muted: #f3f3f3;
  --line: #ffffff;
  --accent: #ffff00;
  --accent-ink: #000000;
  --focus: #ffff00;
  --header: #000000;
  --toolbar: #111111;
  --shadow: none;
}

body.high-contrast button,
body.high-contrast .select-control {
  background: #000000;
  border-color: #ffffff;
  color: #ffffff;
}

body.high-contrast button:hover,
body.high-contrast .select-control:hover {
  background: #111111;
  border-color: #ffff00;
}

body.high-contrast button.active,
body.high-contrast .view-menu button.active {
  background: #ffff00;
  border-color: #ffff00;
  color: #000000;
  box-shadow: none;
}

body.high-contrast .pause-button,
body.high-contrast .details-button,
body.high-contrast .finish-button,
body.high-contrast #saveStatus,
body.high-contrast .clock-display {
  border-color: #ffffff;
  background: #000000;
  color: #ffffff !important;
}

body.high-contrast .finish-intro {
  border-color: #ffff00;
  background: #000000;
  color: #ffffff;
}

body.high-contrast .finish-panel.is-complete .setup-notice {
  background: #000000;
  color: #ffffff;
}

body.high-contrast #completeSessionButton:not(:disabled) {
  border-color: #ff6b6b;
  background: #b52f37;
  color: #ffffff;
}

body.large-font {
  --editor-size: 28px;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .status-line {
    justify-content: flex-start;
  }

  button {
    flex: 1 1 132px;
  }

  .toolbar-end {
    margin-left: 0;
    width: 100%;
  }

  .toolbar-end button {
    flex: 1 1 auto;
  }

  .view-menu {
    left: 14px;
    right: 14px;
    width: auto;
  }

  .select-control {
    flex: 1 1 160px;
    justify-content: space-between;
  }

  #editor {
    min-height: calc(100vh - 320px);
    padding: 18px;
    font-size: max(18px, var(--editor-size));
    border-radius: 6px;
  }

  .editor-surface {
    min-height: calc(100vh - 320px);
    grid-template-columns: minmax(0, 1fr) 10px;
    gap: 7px;
  }
}

@media print {
  @page {
    margin: 0.6in;
  }

  body {
    background: #ffffff;
  }

  .topbar,
  .toolbar,
  .notice,
  .word-panel {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .editor-wrap {
    display: none !important;
  }

  .print-output {
    display: block;
    color: #000000;
    font-size: 12pt;
    line-height: 1.5;
    margin: 0;
    padding: 0;
  }

  .print-pages {
    display: block;
  }

  .print-page {
    box-sizing: border-box;
    height: 9.35in;
    padding-top: 0.3in;
    break-after: page;
    page-break-after: always;
  }

  .print-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .print-page-header {
    color: #333333;
    font-size: 9pt;
  }
}
