@font-face { font-family: Newsreader; src: url('./assets/newsreader.woff2'); font-style: normal; font-weight: 400; font-display: swap; }
@font-face { font-family: "Inter Tight"; src: url('./assets/inter-tight.woff2'); font-style: normal; font-weight: 400 700; font-display: swap; }
:root {
  color-scheme: light;
  --paper: #eeebe3;
  --atlas: url('./assets/cover-atlas.jpg');
  --page-gutter: clamp(16px, 3vw, 48px);
  --sheet: #f3ecdd;
  --ink: #27231d;
  --subtle: #675f52;
  --rule: #322b2377;
  --cobalt: #293e89;
  --serif: Georgia, "Songti SC", SimSun, serif;
  --sans: "Instrument Sans", system-ui, "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", Consolas, "Microsoft YaHei", monospace;
  --ease: cubic-bezier(.2,.75,.24,1);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; min-height: 100dvh; padding: 0 var(--page-gutter); display: flex; flex-direction: column; }
body, .workbench {
  background-image: radial-gradient(ellipse at 45% 38%, #fffbf24f, transparent 76%),
    repeating-linear-gradient(105deg, #39231003 0 1px, transparent 1px 4px);
}
button, a, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--rule); background: transparent; }
button:disabled { cursor: default; opacity: .45; }
button:not(:disabled):hover { color: var(--cobalt); }
a { text-decoration: none; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--cobalt);
  outline-offset: 3px;
}
kbd { font: 11px var(--mono); color: var(--subtle); border: 1px solid var(--rule); padding: 2px 5px; }
.topbar { display: flex; align-items: center; gap: clamp(10px, 2vw, 26px); min-height: 70px; }
.brand { font: 700 clamp(24px, 3vw, 38px)/1 var(--serif); letter-spacing: -.045em; }
.brand-description { border-left: 1px solid var(--rule); padding-left: clamp(10px, 2vw, 26px); color: var(--subtle); font-size: 13px; white-space: nowrap; }
.search-button, #close-tool { min-height: 36px; padding: 0 12px; font-size: 13px; white-space: nowrap; }
#open-command, #close-tool { margin-left: auto; }
.search-button kbd { margin-left: 12px; border-color: transparent; }
body > .topbar .search-button, .workbench .search-button, #close-tool { border-color: transparent; }
.motion-toggle { display: flex; gap: 4px; align-items: center; font-size: 13px; white-space: nowrap; cursor: pointer; }
.motion-toggle input { accent-color: var(--cobalt); }
.help-trigger { border: 1px solid #322b2360; border-radius: 50%; width: 29px; height: 29px; flex: 0 0 29px; font: 500 16px Georgia,serif; transition: background .25s var(--ease), transform .25s var(--ease); }
.help-trigger:hover { background: #293e8910; transform: rotate(-10deg); }
.help-trigger:active { transform: scale(.9); }
.settings { width: min(430px,calc(100vw - 32px)); max-height: 85dvh; overflow: auto; margin: 82px 24px auto auto; padding: 24px; border: 1px solid var(--rule); color: var(--ink); background: var(--sheet); box-shadow: 0 20px 60px #231b1a38; }
.settings::backdrop { background: #231b1a38; }
.settings header { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 22px; }
.settings h2 { margin: 0; font: 500 23px var(--serif); }
.settings h3 { font: 600 14px var(--sans); margin: 24px 0 14px; }
#close-settings { border: 0; font-size: 24px; width: 32px; height: 32px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid #322b2320; font-size: 14px; }
.setting-row select { max-width: 160px; color: inherit; font: inherit; padding: 5px; background: transparent; border: 1px solid var(--rule); }
.setting-row input { accent-color: var(--cobalt); }
.setting-hint { color: var(--subtle); font-size: 12px; line-height: 1.7; margin: 10px 0 0; }
.shortcut-list { margin: 0; font-size: 12px; }
.shortcut-list > div { display: flex; gap: 14px; justify-content: space-between; align-items: center; margin: 13px 0; }
.shortcut-list dd { margin: 0; text-align: right; }
.shortcut-list dt { flex-shrink: 0; }
main { display: grid; flex: 1; align-items: center; }
.selector { min-width: 0; padding: 30px 0 34px; }
.category-nav { isolation: isolate; width: fit-content; max-width: 100%; display: flex; position: relative; margin: 0 auto 8px; border-bottom: 1px solid #322b2330; }
.category-nav button { position: relative; z-index: 1; min-height: 43px; border: 0; padding: 0 clamp(9px, 2vw, 27px); white-space: nowrap; font: 400 clamp(12px, 1.4vw, 16px) var(--serif); transition: color .22s var(--ease), transform .28s var(--ease); }
.category-nav button::before { content: ""; position: absolute; inset: 4px 3px 5px; background: #293e8910; border-radius: 2px; opacity: 0; transform: scale(.94,.8); transition: opacity .25s var(--ease), transform .3s var(--ease); z-index: -1; }
.category-nav button:hover::before, .category-nav button:focus-visible::before { opacity: 1; transform: scale(1); }
.category-nav button:active { transform: translateY(1px) scale(.96); }
.category-nav button:active::before { background: #293e8920; }
.category-nav button[aria-pressed=true] { color: var(--cobalt); font-weight: 700; }
html[lang=en] .category-nav button { font-family: "Inter Tight", var(--sans); font-size: 13px; padding-inline: clamp(8px,1.8vw,24px); }
.category-nav button:focus-visible { outline: none; text-decoration: underline; text-underline-offset: 5px; }
.category-indicator { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--cobalt); transition: transform .38s var(--ease), width .38s var(--ease); }
.shelf-viewport {
  --height: clamp(218px, min(45svh, 31vw), 400px);
  --spine: calc(var(--height) * .166);
  --depth: calc(var(--height) * .535);
  --left-slot: calc(var(--spine) + var(--height) * .036);
  --right-slot: calc(var(--spine) + var(--height) * .058);
  position: relative;
  margin-inline: calc(-1 * var(--page-gutter));
  height: calc(var(--height) + 116px);
  overflow: clip;
  perspective: 2200px;
  touch-action: pan-y;
  user-select: none;
}
.tool-nav { position: absolute; left: 50%; top: calc(55px + var(--height) / 2); transform-style: preserve-3d; }
.book {
  position: absolute;
  left: calc(var(--spine) / -2);
  top: calc(var(--height) / -2);
  width: var(--spine);
  height: var(--height);
  padding: 0;
  border: 0;
  --slot: var(--left-slot);
  --x: calc(var(--drag) + var(--relative) * var(--slot) + var(--side) * (var(--depth) - var(--spine)) / 2 + min(0, var(--side)) * var(--height) * .075);
  transform-style: preserve-3d;
  transform: translateX(var(--x)) rotateY(0deg);
  transition: transform .62s var(--ease);
}
.book[data-right] { --slot: var(--right-slot); }
.book:not([aria-pressed=true]):hover { transform: translateX(var(--x)) translateY(-24px); }
.book[aria-pressed=true] { transform: translateX(calc(var(--drag) - var(--spine) / 10)) translate3d(0,-13px,56px) rotateZ(-4.5deg) rotateX(var(--tilt-x,0deg)) rotateY(calc(-79deg + var(--tilt-y,0deg))); }
@media (hover: hover) and (pointer: fine) {
  .book[aria-pressed=true]:hover { transform: translateX(calc(var(--drag) - var(--spine) / 10)) translate3d(0,-32px,67px) rotateZ(-3.5deg) rotateX(var(--tilt-x,0deg)) rotateY(calc(-83deg + var(--tilt-y,0deg))); }
}
.outgoing-shelf { pointer-events: none; }
.book[data-new], [data-dragging] .book { transition: none; }
.book:focus-visible { outline: 0; }
.book:focus-visible .book-cover { outline: none; }
.book-spine, .book-cover {
  position: absolute;
  top: 0;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 3px 2px 2px 3px;
  color: #fff5e2;
}
.book-spine {
  inset: 0;
  transform: translateZ(calc(var(--depth) / 2));
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 12% 8%;
  gap: 9%;
  background:
    repeating-linear-gradient(110deg,#fff1 0 1px,transparent 1px 5px),
    linear-gradient(90deg,#160d065c,transparent 15%,#fff2 27%,transparent 77%,#120a065e),
    var(--binding);
  box-shadow: inset 0 0 0 1px #20170e25, 2px 5px 13px -4px #33190624;
}
.spine-label {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font: 700 clamp(13px, 1.6vw, 23px)/1 var(--serif);
  letter-spacing: .035em;
  text-shadow: 0 1px 2px #170f0b65;
}
.spine-stamp {
  width: 100%;
  height: 17%;
  background: var(--atlas) var(--art-x) var(--art-y) / 700% 200% no-repeat;
  box-shadow: inset 0 0 0 1px #fff2, 0 1px 4px #17100958;
}
.book-cover {
  left: calc((var(--spine) - var(--depth)) / 2);
  width: var(--depth);
  transform: rotateY(90deg) translateZ(calc(var(--spine) / 2));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12% 13% 10% 14%;
  text-align: left;
  background-image:
    linear-gradient(90deg,#160e0c70,transparent 7%,transparent 94%,#160e0c44),
    linear-gradient(to bottom,#150f0be6 0%,#150f0b80 23%,transparent 43%,transparent 80%,#150f0bb0 100%),
    var(--atlas);
  background-position: center, center, var(--art-x) var(--art-y);
  background-size: 100% 100%, 100% 100%, 700% 200%;
  background-repeat: no-repeat;
  background-color: var(--binding);
  box-shadow: inset 0 0 0 1px #20170e35, 5px 18px 40px -14px #26170e55;
}
.book-cover strong { font: 700 .94em/1.05 var(--serif); letter-spacing: -.035em; text-wrap: balance; overflow-wrap: anywhere; text-shadow: 0 1px 3px #100b08a8; }
html[lang=en] .book-cover strong { font-size: .78em; }
.book > .book-cover { font-size: calc(var(--height) * .115); }
.cover-category { color: #fff5e2; font: 700 .36em/1.2 var(--sans); letter-spacing: .13em; }
.cover-title-part { display: block; }
#shelf-empty { position: absolute; inset: 0; display: grid; place-content: center; margin: 0; color: var(--subtle); }
.shelf-controls { margin: -31px calc(-1 * var(--page-gutter)) 0; padding: 0 64px; display: grid; place-items: center; min-height: 56px; position: relative; text-align: center; }
.caption { overflow: hidden; padding: 5px 1px 8px; }
.caption-mask { overflow: hidden; }
.caption h1 { margin: 0; font: 400 31px/1.12 Newsreader, var(--serif); letter-spacing: -.01em; overflow-wrap: anywhere; }
.caption p { margin: 9px 0 0; color: var(--cobalt); font: 500 10.5px/1.5 "Inter Tight", var(--sans); letter-spacing: .09em; }
.workbench h2 { margin: 0; font: 700 clamp(26px, 4.1vw, 62px)/1.1 var(--serif); letter-spacing: -.045em; overflow-wrap: anywhere; }
.shelf-arrow:focus-visible { outline: none; background: #293e8910; border-radius: 50%; }
body > .topbar :focus-visible { outline: none; box-shadow: 0 2px var(--cobalt); }
.shelf-arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 46px; font-size: 27px; border: 0; }
#previous-book { left: 14px; }
#next-book { right: 14px; }
footer { display: flex; justify-content: space-between; min-height: 56px; padding: 13px 0; color: var(--subtle); font-size: 12px; }

.workbench {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  padding: 0 clamp(16px, 3vw, 48px) 36px;
  background-color: var(--paper);
  color: var(--ink);
  overflow: auto;
}
.workbench::backdrop { background: transparent; }
.workbench-intro { padding: 24px 16px 21px; display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 168px; }
.workbench-intro p { color: var(--cobalt); margin: 12px 0 0; font: 600 14px var(--serif); }
.workbench h2:focus { outline: none; }
#cover-preview { position: relative; width: 69px; height: 115px; flex: 0 0 69px; transform: rotate(3deg); }
#cover-preview .book-cover { left: 0; width: 100%; transform: none; font-size: 15px; border-left: 7px solid var(--binding); padding-inline: 8%; }
#cover-preview strong { overflow-wrap: anywhere; }
#cover-preview .cover-category { font-size: 7px; }
#tool-view { width: 100%; margin: 0 auto; }
.workbench-head, .tool-option { border: 1px solid var(--rule); display: flex; gap: 8px; align-items: center; padding: 8px 12px; }
.tool-actions, #modes { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.workbench-head button, .editor-head button { min-height: 32px; padding: 3px 10px; font-size: 13px; }
.workbench-head button[aria-pressed=true], .workbench-head .primary { background: var(--cobalt); color: #fff9e9; border-color: var(--cobalt); }
.star-button { margin-left: auto; }
.tool-option { flex-wrap: wrap; border-top: 0; font-size: 13px; }
.tool-option input { background: var(--sheet); border: 1px solid var(--rule); padding: 6px; min-width: 0; }
#regex-pattern { flex: 1; }
#regex-flags { width: 70px; }
.editors { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); border: 1px solid var(--rule); border-top: 0; background: #fffbf224; }
.editor { display: flex; flex-direction: column; min-width: 0; }
.editor + .editor { border-left: 1px solid var(--rule); }
.editor-head, #comparison-editor label { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--rule); padding: 8px 12px; min-height: 48px; font-size: 13px; }
.editor-head button { margin-left: auto; border-color: var(--cobalt); color: var(--cobalt); }
.editor-body { position: relative; display: flex; min-height: clamp(248px, 43dvh, 540px); flex: 1; }
.gutter, .editor textarea, .editor pre { font: 14px/22px var(--mono); tab-size: 2; }
.gutter { text-align: right; flex: 0 0 47px; padding: 12px 9px; white-space: pre; color: var(--subtle); background: #382b1609; border-right: 1px solid #382b162a; overflow: hidden; position: absolute; inset: 0 auto 0 0; width: 47px; }
.editor-layer { flex: 1; min-width: 0; margin-left: 47px; position: relative; }
.editor textarea, .editor pre { color: var(--ink); border: 0; margin: 0; padding: 12px; background: transparent; white-space: pre; }
.editor-layer textarea, .editor pre { position: absolute; inset: 0; width: 100%; height: 100%; overflow: auto; resize: none; }
.editor-layer textarea:focus-visible { outline-offset: -2px; }
.editor textarea[data-highlight] { color: transparent; caret-color: var(--ink); }
.editor pre { pointer-events: none; scrollbar-width: none; }
.token-key { color: #9c3024; }
.token-string { color: #234a99; }
.token-literal { color: #2c5a3c; }
.invalid-token { background: #f1b8a0; color: #6e2518; }
.editor:has(#comparison-editor:not([hidden])) .editor-body { min-height: 165px; }
#comparison-editor { border-top: 1px solid var(--rule); }
#comparison-editor textarea { display: block; width: 100%; min-height: 150px; resize: vertical; }
.error { margin: 0; padding: 10px 12px; background: #a8301911; color: #85291f; font-size: 13px; }
.empty-output { position: absolute; top: 0; left: 59px; right: 12px; color: var(--subtle); pointer-events: none; font-size: 13px; }
.command { width: min(92vw, 540px); max-height: 74dvh; padding: 0; border: 1px solid var(--rule); color: var(--ink); background: var(--sheet); box-shadow: 0 16px 65px #231b1a48; }
.command::backdrop { background: #231b1a65; }
.command-search { display: flex; align-items: center; border-bottom: 1px solid var(--rule); gap: 8px; padding: 10px; }
.command-search input { background: transparent; border: 0; flex: 1; min-width: 0; padding: 8px; }
.command-search button { padding: 4px; border: 0; }
.command-help { display: flex; justify-content: space-between; border-top: 1px solid var(--rule); padding: 10px; font-size: 12px; }
#command-list { margin: 0; padding: 6px; max-height: 48dvh; overflow: auto; list-style: none; }
#command-list li { display: flex; gap: 12px; align-items: center; cursor: pointer; padding: 8px 10px; }
#command-list li[aria-selected=true] { background: var(--cobalt); color: #fff9e9; }
.command-icon { width: 28px; font: 14px var(--mono); }
#command-empty { padding: 0 14px 8px; }
.sr-only { position: absolute; margin: -1px; padding: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[data-motion=off] *, [data-motion=off] *::before, [data-motion=off] *::after { transition: none !important; animation: none !important; }

@media (max-width: 700px) {
  html[lang=en] .category-nav button { font-size: 12px; padding-inline: 9px; }
  .settings { margin: 70px auto auto; padding: 20px; }
  .caption h1 { font-size: 24px; }
  .topbar { min-height: 60px; gap: 9px; }
  .brand-description, .search-button kbd { display: none; }
  .search-button, #close-tool { padding: 0 7px; }
  .selector { padding-top: 21px; }
  .shelf-viewport { --height: clamp(175px, min(53vw, 37svh), 280px); height: calc(var(--height) + 100px); }
  .tool-nav { top: calc(42px + var(--height) / 2); }
  .shelf-controls { margin-top: -23px; padding-inline: 51px; }
  .shelf-arrow { width: 44px; }
  #previous-book { left: 4px; }
  #next-book { right: 4px; }
  .workbench-intro { min-height: 136px; padding: 14px 5px; }
  #cover-preview { height: 92px; flex-basis: 55px; }
  #cover-preview .book-cover { font-size: 12px; }
  .editors { grid-template-columns: 1fr; }
  .editor + .editor { border-left: 0; border-top: 1px solid var(--rule); }
  .editor-body { min-height: 230px; }
  .workbench-head { padding-inline: 6px; }
  .workbench-head button { padding-inline: 6px; }
}

@media (max-width: 350px) {
  .category-nav button { padding-inline: 5px; }
  .workbench .brand { font-size: 20px; }
}
