:root {
  color-scheme: dark;
  --app-bg: #111418;
  --stage-bg: #0c0f13;
  --panel-bg: #171d24;
  --panel-strong: #151a20;
  --button-bg: #1b222b;
  --button-hover: #202a36;
  --control-bg: #27313c;
  --control-hover: #324050;
  --control-text: #ffffff;
  --border: #33404f;
  --border-strong: #303a46;
  --text: #eef2f6;
  --muted: #aeb8c4;
  --soft-text: #d6dee8;
  --accent: #2d6fd3;
  --accent-hover: #347ce8;
  --accent-border: #6ba8ff;
  --accent-soft: #10233f;
  --accent-soft-text: #9fc5ff;
  --selected: #ffcf5a;
  --counter-bg: #242d37;
  --canvas-border: #3b4653;
  --error: #ff9f9f;
  --stage-label: #ffffff;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  background: var(--app-bg);
  color: var(--text);
}

body[data-theme="green"] {
  --app-bg: #101512;
  --stage-bg: #0a0f0d;
  --panel-bg: #151d18;
  --panel-strong: #121a15;
  --button-bg: #18231d;
  --button-hover: #1f2d25;
  --control-bg: #203328;
  --control-hover: #294132;
  --border: #2f4438;
  --border-strong: #28382f;
  --accent: #23875a;
  --accent-hover: #2a9d68;
  --accent-border: #60c98f;
  --accent-soft: #102a1e;
  --accent-soft-text: #9de6ba;
  --selected: #f3cf65;
  --counter-bg: #203127;
  --canvas-border: #385447;
}

body[data-theme="amber"] {
  --app-bg: #161310;
  --stage-bg: #0f0c09;
  --panel-bg: #201811;
  --panel-strong: #1c150f;
  --button-bg: #261b12;
  --button-hover: #302216;
  --control-bg: #3b2a18;
  --control-hover: #49331d;
  --border: #4a3826;
  --border-strong: #3b2d20;
  --accent: #b76818;
  --accent-hover: #d1791e;
  --accent-border: #f1aa54;
  --accent-soft: #392211;
  --accent-soft-text: #ffd39a;
  --selected: #74d6ff;
  --counter-bg: #352515;
  --canvas-border: #61452c;
}

body[data-theme="cyan"] {
  --app-bg: #0e1517;
  --stage-bg: #081012;
  --panel-bg: #121d21;
  --panel-strong: #101a1e;
  --button-bg: #15252a;
  --button-hover: #1b3037;
  --control-bg: #1d3a42;
  --control-hover: #244852;
  --border: #2d4850;
  --border-strong: #263d45;
  --accent: #168aa0;
  --accent-hover: #1aa0b8;
  --accent-border: #67d8e9;
  --accent-soft: #102f37;
  --accent-soft-text: #a0edf5;
  --selected: #f2c84b;
  --counter-bg: #1c333a;
  --canvas-border: #365b64;
}

body[data-theme="plum"] {
  --app-bg: #141219;
  --stage-bg: #0d0b12;
  --panel-bg: #1d1824;
  --panel-strong: #19151f;
  --button-bg: #231c2c;
  --button-hover: #2c2338;
  --control-bg: #332742;
  --control-hover: #403153;
  --border: #463757;
  --border-strong: #3a2d49;
  --accent: #7556d8;
  --accent-hover: #8667ed;
  --accent-border: #b29bff;
  --accent-soft: #281d4d;
  --accent-soft-text: #d0c2ff;
  --selected: #7de0c2;
  --counter-bg: #2c2438;
  --canvas-border: #55466a;
}

body[data-theme="paper"] {
  color-scheme: light;
  --app-bg: #e8edf2;
  --stage-bg: #dfe5eb;
  --panel-bg: #f7f9fb;
  --panel-strong: #eef3f7;
  --button-bg: #ffffff;
  --button-hover: #eef4fa;
  --control-bg: #ffffff;
  --control-hover: #ecf3fa;
  --control-text: #14202b;
  --border: #c6d0da;
  --border-strong: #b8c5d0;
  --text: #14202b;
  --muted: #516273;
  --soft-text: #243443;
  --accent: #245f9f;
  --accent-hover: #1e6dbb;
  --accent-border: #3e8bd8;
  --accent-soft: #dcecff;
  --accent-soft-text: #17466f;
  --selected: #b05c00;
  --counter-bg: #dde7f0;
  --canvas-border: #b4c0cc;
  --error: #9b2226;
  --stage-label: #14202b;
}

body[data-theme="steel"] {
  --app-bg: #111417;
  --stage-bg: #090c0f;
  --panel-bg: #181c20;
  --panel-strong: #15191d;
  --button-bg: #20262b;
  --button-hover: #2a3238;
  --control-bg: #2b333a;
  --control-hover: #35404a;
  --border: #3e474f;
  --border-strong: #343c44;
  --accent: #607d96;
  --accent-hover: #6f90ad;
  --accent-border: #a9c0d4;
  --accent-soft: #202d38;
  --accent-soft-text: #d4e2ee;
  --selected: #e2c45d;
  --counter-bg: #272f36;
  --canvas-border: #505c66;
}

body.theme-pink {
  --app-bg: #ffb7df;
  --stage-bg: #ff8acb;
  --panel-bg: #ff4fb1;
  --panel-strong: #ff2fa2;
  --button-bg: #ff7ac6;
  --button-hover: #ff97d4;
  --control-bg: #ff1493;
  --control-hover: #ff43ae;
  --control-text: #ffffff;
  --border: #ff008c;
  --border-strong: #d60078;
  --text: #4b0030;
  --muted: #7a004e;
  --soft-text: #5a0039;
  --accent: #ff008c;
  --accent-hover: #ff2fa2;
  --accent-border: #fff0f9;
  --accent-soft: #ffe0f3;
  --accent-soft-text: #8f005a;
  --selected: #ffffff;
  --counter-bg: #ffd3eb;
  --canvas-border: #ff008c;
  --error: #700018;
  --stage-label: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  background: var(--app-bg);
  overflow: hidden;
}

#app {
  width: 100vw;
  min-height: 100vh;
  background: var(--app-bg);
}

body.rotated #app {
  width: 100vh;
  height: 100vw;
  min-height: 100vw;
  overflow: auto;
  transform: rotate(90deg) translateY(-100%);
  transform-origin: top left;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.login-shell {
  display: grid;
  place-items: center;
  width: 100vw;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, color-mix(in srgb, var(--accent) 22%, transparent), transparent 34rem),
    var(--app-bg);
  padding: 20px;
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-bg);
  padding: 28px;
  box-shadow: 0 18px 48px rgb(0 0 0 / 32%);
}

.login-heading {
  display: grid;
  gap: 8px;
}

.login-card label {
  display: grid;
  gap: 8px;
  color: var(--soft-text);
  font-weight: 700;
}

.login-card input {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--button-bg);
  color: var(--text);
  padding: 0 14px;
}

.login-card input:focus-visible {
  border-color: var(--accent-border);
  outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

.login-button {
  min-height: 54px;
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

.login-button:hover {
  background: var(--accent-hover);
}

.login-error {
  border: 1px solid color-mix(in srgb, var(--error) 60%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--error) 13%, var(--panel-bg));
  color: var(--error);
  padding: 10px 12px;
}

.shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

body.rotated .shell {
  width: min(1120px, calc(100vh - 32px));
}

.topbar,
.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-actions {
  position: relative;
  display: flex;
  gap: 8px;
}

.secret-theme-button {
  position: absolute;
  right: 0;
  bottom: calc(100% + 4px);
  width: 96px;
  height: 32px;
  border: 0;
  background: transparent;
  cursor: default;
}

.brand-block,
.viewer-title {
  display: grid;
  gap: 6px;
}

.brand-mark {
  width: fit-content;
  border: 1px solid var(--accent-border);
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

p,
small {
  color: var(--muted);
}

.utility-button,
.tabs button {
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--text);
  padding: 0 18px;
  cursor: pointer;
}

.utility-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.settings-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 22px 0 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  padding: 16px;
}

.settings-panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.settings-groups {
  display: grid;
  gap: 10px;
  min-width: min(620px, 100%);
}

.settings-group {
  border-radius: 8px;
}

.mode-switch,
.theme-switch {
  display: grid;
  gap: 6px;
}

.mode-switch {
  grid-template-columns: repeat(3, 1fr);
}

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

.mode-switch button,
.theme-switch button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--text);
  padding: 0 16px;
  cursor: pointer;
}

.theme-switch button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.theme-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent);
}

.theme-swatch[data-theme-swatch="blue"] {
  background: #2d6fd3;
}

.theme-swatch[data-theme-swatch="green"] {
  background: #23875a;
}

.theme-swatch[data-theme-swatch="amber"] {
  background: #b76818;
}

.theme-swatch[data-theme-swatch="cyan"] {
  background: #168aa0;
}

.theme-swatch[data-theme-swatch="plum"] {
  background: #7556d8;
}

.theme-swatch[data-theme-swatch="paper"] {
  background: #e8edf2;
}

.theme-swatch[data-theme-swatch="steel"] {
  background: #607d96;
}

.mode-switch .active,
.theme-switch .active {
  border-color: var(--accent-border);
  background: var(--accent);
  color: #ffffff;
}

.settings-group.keyboard-focus {
  outline: 3px solid var(--selected);
  outline-offset: 6px;
}

.utility-button:hover,
.tabs button:hover,
.job-button:hover {
  border-color: var(--accent-border);
  background: var(--button-hover);
}

.utility-button:active,
.tabs button:active,
.job-button:active {
  transform: translateY(1px);
}

.job-button.selected {
  border-color: var(--selected);
  box-shadow: inset 4px 0 0 var(--selected);
}

.utility-button:focus-visible,
.tabs button:focus-visible,
.job-button:focus-visible,
.controls button:focus-visible,
.login-button:focus-visible {
  outline: 3px solid var(--selected);
  outline-offset: 2px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 24px 0 16px;
}

.tabs .active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent-border);
}

.job-list {
  display: grid;
  gap: 10px;
}

.job-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 76px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  padding: 16px 18px;
  cursor: pointer;
  text-align: left;
}

.job-button span:first-child {
  display: grid;
  gap: 5px;
}

.job-button strong {
  font-size: 22px;
}

.job-meta {
  border-radius: 4px;
  background: var(--counter-bg);
  color: var(--soft-text);
  padding: 6px 10px;
  white-space: nowrap;
}

.empty,
.loading {
  margin: 52px auto;
  color: var(--muted);
  text-align: center;
}

.error {
  color: var(--error);
}

.unrecognized-list {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  margin: 0;
  padding: 16px 16px 16px 40px;
}

.unrecognized-list li {
  padding: 6px 0;
  color: var(--soft-text);
}

.viewer {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  background: var(--stage-bg);
}

body.rotated .viewer {
  height: 100vw;
}

.viewer-header {
  min-height: 78px;
  padding: 10px 16px;
  background: var(--panel-strong);
  border-bottom: 1px solid var(--border-strong);
}

.viewer-header h1 {
  font-size: 24px;
}

.viewer-header-actions {
  display: flex;
  gap: 8px;
}

.counter {
  min-width: 86px;
  border-radius: 4px;
  background: var(--counter-bg);
  color: var(--text);
  padding: 9px 10px;
  text-align: center;
  font-weight: 800;
}

.pdf-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 12px;
  background: var(--stage-bg);
  overflow: hidden;
}

.pdf-stage-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
}

.pdf-pages {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  max-width: 100%;
  max-height: 100%;
  transform-origin: center;
}

.pdf-stage.spread .pdf-pages {
  gap: 2px;
}

.pdf-stage canvas {
  display: block;
  border: 1px solid var(--canvas-border);
  background: #ffffff;
  box-shadow: 0 8px 22px rgb(0 0 0 / 35%);
}

.pdf-stage canvas[hidden] {
  display: none;
}

.keyboard-letterbox {
  display: none;
  z-index: 4;
  color: var(--stage-label);
  overflow: hidden;
  pointer-events: none;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keyboard-letterbox-bottom {
  align-items: center;
  justify-content: center;
}

.page-marker {
  display: inline-grid;
  justify-items: center;
  min-width: 92px;
  color: var(--stage-label);
  font-size: 74px;
  font-weight: 800;
  line-height: 0.92;
}

.page-marker strong {
  color: var(--stage-label);
  font-size: 74px;
  line-height: 0.92;
}

.page-marker-single {
  display: inline-block;
  min-width: 0;
  font-size: 68px;
  line-height: 1;
}

.spread-indicators {
  display: none;
  justify-content: space-between;
  padding: 0 max(48px, calc((100% - min(100%, 1600px)) / 2 + 48px));
}

body.rotated .pdf-stage.spread {
  grid-template-columns: minmax(110px, 13vw) minmax(0, 1fr) minmax(110px, 13vw);
  grid-template-rows: 1fr;
  padding: 0;
}

body.rotated .pdf-stage.spread .keyboard-letterbox-top {
  display: none;
}

body.rotated .pdf-stage.spread .pdf-stage-body {
  grid-column: 2;
  grid-row: 1;
}

body.rotated .pdf-stage.spread .keyboard-letterbox-bottom {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 1;
  grid-template-columns: minmax(110px, 13vw) minmax(0, 1fr) minmax(110px, 13vw);
  align-items: center;
  justify-content: stretch;
  padding: 0;
}

body.rotated .pdf-stage.spread .page-marker {
  justify-self: center;
  width: min(11vw, 150px);
}

body.rotated .pdf-stage.spread .page-marker:first-child {
  grid-column: 1;
}

body.rotated .pdf-stage.spread .page-marker:last-child {
  grid-column: 3;
}

.pdf-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  border: 1px solid var(--canvas-border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel-strong) 88%, transparent);
  color: var(--soft-text);
  padding: 10px 14px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.pdf-loading[hidden] {
  display: none;
}

.touch-zone {
  display: none;
  position: absolute;
  top: 12px;
  bottom: 12px;
  width: min(28%, 220px);
  border: 0;
  background: transparent;
  color: rgb(8 10 12 / 50%);
  font-size: 164px;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
}

.touch-zone-left {
  left: 12px;
}

.touch-zone-right {
  right: 12px;
}

.controls {
  position: fixed;
  left: 50%;
  bottom: 14px;
  z-index: 15;
  display: grid;
  grid-template-columns: 110px 92px 110px 96px;
  gap: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-strong) 88%, transparent);
  padding: 8px;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgb(0 0 0 / 28%);
}

.controls button {
  min-height: 58px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--control-bg);
  color: var(--control-text);
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
}

.controls button:hover {
  background: var(--control-hover);
  border-color: var(--accent-border);
}

.controls button:active {
  transform: translateY(1px);
}

.controls button[data-action="book"] {
  background: var(--accent);
  border-color: var(--accent-border);
  color: #ffffff;
}

.controls button[data-action="book"]:hover {
  background: var(--accent-hover);
}

body.theme-pink .touch-zone {
  color: rgb(8 10 12 / 50%);
}

body[data-mode="keyboard"] .viewer-header,
body[data-mode="keyboard"] .controls {
  display: none;
}

body[data-mode="keyboard"] .viewer {
  grid-template-rows: 1fr;
}

body[data-mode="keyboard"] .pdf-stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  padding: 0 12px;
}

body[data-mode="keyboard"] .pdf-stage-body {
  grid-row: 1;
  width: 100%;
  height: 100%;
}

body[data-mode="keyboard"] .keyboard-letterbox {
  display: flex;
}

body[data-mode="keyboard"] .keyboard-letterbox-top {
  display: none;
}

body[data-mode="keyboard"] .keyboard-letterbox-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 26px;
  min-height: 80px;
}

body.rotated[data-mode="keyboard"] .pdf-stage.spread .keyboard-letterbox-bottom {
  position: static;
  min-height: 0;
}

body[data-mode="keyboard"] .spread-indicators {
  display: flex;
}

body[data-mode="touch"] .controls {
  display: none;
}

body[data-mode="touch"] .viewer {
  grid-template-rows: auto 1fr;
}

body[data-mode="touch"] .touch-zone {
  display: block;
}

body[data-mode="touch"] .touch-zone:active {
  opacity: 0.72;
}

@media (max-width: 700px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  body:has(.viewer) {
    height: 100vh;
    overflow: hidden;
  }

  .login-shell {
    align-items: start;
    padding: 18px;
  }

  .login-card {
    margin-top: 20px;
    padding: 22px;
  }

  .shell {
    width: min(100vw - 20px, 1120px);
    padding: 18px 0 28px;
  }

  body.rotated .shell {
    width: min(100vh - 20px, 1120px);
  }

  .topbar,
  .viewer-header {
    display: grid;
    align-items: flex-start;
  }

  .topbar-actions,
  .viewer-header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .utility-button,
  .tabs button {
    min-height: 50px;
    padding: 0 12px;
  }

  .settings-panel {
    display: grid;
    padding: 14px;
  }

  .mode-switch,
  .theme-switch {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 24px;
  }

  .tabs {
    display: grid;
    grid-template-columns: 1fr;
  }

  .job-button {
    display: grid;
    min-height: 92px;
    padding: 16px;
  }

  .job-button strong {
    font-size: 20px;
  }

  .job-meta {
    width: fit-content;
    white-space: normal;
  }

  .viewer {
    height: 100vh;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .viewer-header {
    min-height: 0;
    padding: 10px;
  }

  .viewer-header h1 {
    font-size: 20px;
  }

  .counter {
    min-width: 0;
    width: fit-content;
  }

  .pdf-stage {
    padding: 8px;
  }

  .controls {
    position: static;
    grid-template-columns: 1fr 76px 1fr;
    width: 100%;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 0;
    transform: none;
  }

  .controls button {
    min-height: 64px;
    font-size: 18px;
  }

  .controls button[data-action="rotate"] {
    display: none;
  }

  body[data-mode="touch"] .viewer {
    grid-template-rows: auto minmax(0, 1fr);
  }

  body[data-mode="touch"] .touch-zone {
    width: 34%;
    font-size: 96px;
  }
}

@media (max-width: 420px) {
  .brand-mark {
    font-size: 11px;
  }

  .topbar-actions,
  .viewer-header-actions {
    grid-template-columns: 1fr;
  }

  .viewer-title {
    gap: 4px;
  }

  .viewer-header p {
    font-size: 13px;
  }
}
