:root {
  color-scheme: light;
  --page-background: #f7f6f2;
  --text-color: #23332f;
  --surface: #fff;
  --surface-alt: #fcfcfa;
  --border-color: #e4e5dc;
  --muted-color: #728078;
  --subtle-color: #64716c;
  --toc-line-color: #7f9588;
  --vocab-background: #eef3ec;
  --vocab-border: #9db5a5;
  --sentence-font-size: 22px;
  font-family: "Avenir Next", Avenir, "Hiragino Kaku Gothic ProN", sans-serif;
  color: var(--text-color);
  background: var(--page-background);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 86% 4%, rgb(230 237 225 / 72%), transparent 29rem),
    var(--page-background);
}

button,
textarea {
  font: inherit;
}

.page-shell {
  width: min(100% - 48px, 1180px);
  margin: 0 auto;
  padding: 28px 0 52px;
}

.topbar,
.brand,
.form-footer,
.result-heading,
.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
  gap: 14px;
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  background: var(--page-background);
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  justify-content: flex-start;
  gap: 10px;
  color: inherit;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  display: block;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.brand-light {
  color: var(--muted-color);
  font-weight: 500;
}

.edition-label,
.eyebrow {
  color: var(--muted-color);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
}

.toolbar,
.font-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.theme-select-label {
  margin: 0;
  color: var(--muted-color);
  font-size: 11px;
}

.toolbar-select {
  min-height: 34px;
  padding: 0 28px 0 9px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-color);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.toolbar-select:focus-visible {
  outline: 2px solid #70917e;
  outline-offset: 2px;
}

.toolbar-select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.toolbar-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-color);
  cursor: pointer;
  font-size: 12px;
}

.toolbar-button:hover:not(:disabled) {
  border-color: #70917e;
  background: var(--surface-alt);
}

.toolbar-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.help-dialog {
  width: min(1050px, calc(100vw - 32px));
  max-width: none;
  max-height: min(82vh, 760px);
  padding: 22px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text-color);
  box-shadow: 0 24px 80px rgb(0 0 0 / 25%);
}

.delete-confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-color);
  box-shadow: 0 24px 80px rgb(0 0 0 / 25%);
}

.delete-confirm-dialog::backdrop {
  background: rgb(18 27 22 / 55%);
  backdrop-filter: blur(2px);
}

.delete-confirm-dialog h2 {
  margin-bottom: 8px;
  font-size: 19px;
}

.delete-confirm-dialog p {
  margin: 0;
  color: var(--subtle-color);
  font-size: 13px;
  line-height: 1.5;
}

.delete-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.delete-confirm-yes {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #a52b2b;
  border-radius: 7px;
  background: #b83232;
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.delete-confirm-yes:hover {
  background: #982626;
}

.help-dialog::backdrop,
.toc-dialog::backdrop {
  background: rgb(18 27 22 / 55%);
  backdrop-filter: blur(2px);
}

.toc-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  padding: 22px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-color);
  box-shadow: 0 24px 80px rgb(0 0 0 / 25%);
}

.note-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-title-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-alt);
  color: inherit;
  font: inherit;
  font-size: 17px;
}

.note-title-input[hidden],
.note-title[hidden] {
  display: none;
}

.note-title[role="button"] {
  cursor: text;
}

.note-title[role="button"]:hover,
.note-title[role="button"]:focus-visible {
  background: var(--surface-alt);
}

.clip-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 12px;
  margin: 8px 0 12px;
}

.clip-toolbar .toc-add-button {
  margin-left: 0;
}

#copy-button[data-copy-status="copied"] {
  color: #47745b;
}

#copy-button[data-copy-status="failed"] {
  color: #b42318;
}

#clip-text-form[hidden],
#sentence-output[hidden],
#result-note[hidden] {
  display: none;
}

.toc-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--subtle-color);
  font-size: 12px;
  font-weight: 600;
}

.toc-breadcrumb[hidden] {
  display: none;
}

.toc-breadcrumb-separator {
  color: var(--muted-color);
}

.toc-breadcrumb-link {
  padding: 2px 4px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.toc-breadcrumb-text {
  padding: 2px 4px;
}

.toc-breadcrumb-current {
  overflow: hidden;
  max-width: 32ch;
  padding: 2px 4px;
  color: var(--text-color);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-breadcrumb-link:hover,
.toc-breadcrumb-link:focus-visible {
  background: rgb(127 127 127 / 18%);
  text-decoration: underline;
  outline: none;
}

.toc-row.current .toc-title,
.toc-row.current .toc-leaf-choice {
  background: rgb(127 127 127 / 22%);
  border-radius: 4px;
  padding: 0 6px;
}

.toc-entry.current .toc-entry-open {
  border-color: var(--muted-color);
  background: rgb(127 127 127 / 22%);
  font-weight: 700;
}

.toc-browse-dialog {
  margin: 5vh auto 5vh 16px;
  width: fit-content;
  min-width: min(360px, calc(100vw - 32px));
  max-width: 90vw;
  height: auto;
  max-height: 90vh;
  overflow-y: auto;
}

.toc-browse-dialog[open] {
  display: block;
}

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

.toc-tree:not(.editing) .toc-actions,
.toc-tree:not(.editing) .toc-entry .toc-action {
  display: none;
}

.toc-tree {
  margin-top: 14px;
  font-size: 14px;
}

.toc-children {
  margin-left: 18px;
  padding-left: 10px;
  border-left: 2px solid var(--toc-line-color);
}

.toc-node > summary {
  cursor: pointer;
}

.toc-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.toc-title {
  font-weight: 600;
}

.toc-actions {
  display: inline-flex;
  gap: 2px;
}

.toc-action,
.toc-add-button {
  min-width: 26px;
  height: 26px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-alt);
  color: inherit;
  cursor: pointer;
  transition: transform 150ms ease, color 150ms ease;
}

.toc-action:hover:not(:disabled),
.toc-add-button:hover:not(:disabled) {
  transform: translateY(-1px);
  color: #47745b;
}

.toc-add-button {
  margin-left: 12px;
  font-size: 18px;
  line-height: 1;
}

#toc-assign-button[aria-pressed="true"] .bookmark-icon {
  fill: currentColor;
}

#toc-assign-button[aria-pressed="true"] {
  color: var(--text-color);
}

#toc-assign-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.toc-leaf-choice,
.toc-entry-open {
  padding: 4px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-alt);
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.toc-leaf-choice:hover,
.toc-entry-open:hover:not(:disabled) {
  border-color: var(--muted-color);
}

.toc-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}

.toc-entry-open {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.help-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.help-dialog-header .eyebrow {
  margin-bottom: 5px;
}

.help-dialog-header h2 {
  font-size: 22px;
}

.help-intro {
  margin: 12px 0 17px;
  color: var(--subtle-color);
  font-size: 13px;
  line-height: 1.6;
}

.help-search-label {
  margin-bottom: 6px;
  font-size: 12px;
}

.help-search {
  width: 100%;
  margin-bottom: 13px;
  padding: 9px 11px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  outline: none;
  background: var(--surface-alt);
  color: var(--text-color);
  font: inherit;
  font-size: 13px;
}

.help-search:focus {
  border-color: #70917e;
  box-shadow: 0 0 0 3px rgb(91 130 106 / 13%);
}

.help-table-wrap {
  max-height: min(52vh, 480px);
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
}

.help-table th,
.help-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.help-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-alt);
  color: var(--muted-color);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.help-table tbody tr:last-child td {
  border-bottom: 0;
}

.help-table tbody tr:hover {
  background: var(--surface-alt);
}

.help-table code {
  display: block;
  color: #47745b;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.help-tag-label {
  display: block;
  margin-top: 2px;
  color: var(--muted-color);
  font-size: 10px;
}

.help-empty,
.help-loading,
.help-error {
  padding: 18px !important;
  color: var(--muted-color);
  text-align: center;
}

.help-error {
  color: #a53f38;
}

.font-button {
  min-width: 38px;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
}

.settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.intro {
  max-width: 650px;
  padding: 56px 0 31px;
}

.intro .eyebrow,
.result-heading .eyebrow {
  margin: 0 0 12px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 13px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: clamp(32px, 5vw, 46px);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 1.2;
}

.intro-copy {
  max-width: 550px;
  margin-bottom: 0;
  color: var(--subtle-color);
  font-size: 15px;
  line-height: 1.75;
}

.workspace {
  position: sticky;
  top: 20px;
  overflow: visible;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 16px 44px rgb(34 47 39 / 6%);
}

/* The sticky workspace is its own stacking context, so lift it above the
   vocabulary panel while a word popup is open. */
.workspace:has(.dictionary-word:hover, .dictionary-word:focus-visible) {
  z-index: 20;
}

.reading-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  align-items: start;
  gap: 24px;
  margin-top: 24px;
}

.workspace:not(:has(> .result-panel:not([hidden]))) {
  display: none;
}

.reading-layout:not(:has(.result-panel:not([hidden]))) {
  grid-template-columns: minmax(0, 1fr);
}

#sentence-form {
  padding: 25px 27px 22px;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
}

textarea {
  display: block;
  width: 100%;
  min-height: 142px;
  padding: 15px 16px;
  resize: vertical;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  outline: none;
  background: var(--surface-alt);
  color: var(--text-color);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 16px;
  line-height: 1.9;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

textarea:focus {
  border-color: #70917e;
  box-shadow: 0 0 0 3px rgb(91 130 106 / 13%);
}

textarea::placeholder {
  color: #a4ada6;
}

.form-footer {
  padding-top: 16px;
}

.input-hint,
.match-count,
.result-note,
.history-note {
  margin: 0;
  color: var(--muted-color);
  font-size: 12px;
}

.form-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.clear-button {
  min-height: 42px;
  padding: 0 14px;
  font-size: 13px;
}

#process-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  gap: 15px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: #315d4c;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 150ms ease, transform 150ms ease;
}

#process-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #264b3c;
}

#process-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.result-panel {
  padding: 24px 27px 23px;
}

#sentence-form:not([hidden]) + .result-panel {
  border-top: 1px solid var(--border-color);
}

.result-heading {
  align-items: flex-end;
  margin-bottom: 19px;
}

h2 {
  margin: 0;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 19px;
  font-weight: 500;
}

.match-count {
  padding-bottom: 3px;
  white-space: nowrap;
}

.sentence-output {
  margin: 0;
  color: var(--text-color);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: var(--sentence-font-size);
  line-height: 2.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dictionary-word {
  position: relative;
  display: inline;
  padding: 0 1px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: inherit;
  cursor: help;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  text-decoration: underline;
  text-decoration-color: #77a189;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}

.dictionary-word:hover,
.dictionary-word:focus-visible {
  z-index: 20;
  outline: none;
  background: #eff5ef;
}

:root .sentence-output.pointer-lookup-active .dictionary-word:hover {
  background: transparent;
}

.lookup-character {
  cursor: help;
}

.lookup-character.lookup-match {
  background: color-mix(in srgb, #77a189 35%, var(--surface));
  text-decoration: underline;
  text-decoration-color: #47745b;
}

.sentence-output.pointer-lookup-active .dictionary-word .dictionary-tooltip {
  display: none;
}

.dictionary-tooltip.hover-lookup-tooltip {
  display: block;
  z-index: 40;
}

@media (hover: hover) {
  :root .sentence-output .dictionary-word:hover:not(:focus-visible) {
    background: transparent;
  }

  .sentence-output .dictionary-word:hover:not(:focus-visible) .dictionary-tooltip {
    display: none;
  }
}

ruby {
  ruby-align: center;
}

rt {
  color: #47745b;
  font-family: "Avenir Next", Avenir, sans-serif;
  font-size: 0.48em;
  line-height: 1;
}

.furigana-hidden rt {
  display: none;
}

.reading-romaji,
.romaji-furigana .reading-kana {
  display: none;
}

.romaji-furigana .reading-romaji {
  display: inline;
}

.accent-number-hidden .accent-number {
  display: none;
}

.settings-dialog {
  width: min(420px, calc(100vw - 32px));
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0;
  border-top: 1px solid var(--border-color);
}

.settings-item:first-of-type {
  margin-top: 14px;
}

.settings-label {
  margin: 0 0 2px;
  font-size: 14px;
  font-weight: 600;
}

.settings-hint {
  margin: 0;
  color: var(--subtle-color);
  font-size: 12px;
  line-height: 1.4;
}

.switch {
  position: relative;
  flex: none;
  width: 42px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--muted-color);
  cursor: pointer;
  transition: background 0.15s;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  content: "";
  transition: transform 0.15s;
}

.switch[aria-checked="true"] {
  background: #3f8a5f;
}

.switch[aria-checked="true"]::after {
  transform: translateX(18px);
}

.switch:focus-visible {
  outline: 2px solid #70917e;
  outline-offset: 2px;
}

.switch:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.dictionary-tooltip {
  position: absolute;
  z-index: 3;
  bottom: calc(100% + 9px);
  left: 50%;
  display: none;
  width: min(320px, 80vw);
  max-height: 50vh;
  padding: 12px 14px;
  overflow-y: auto;
  transform: translateX(-50%);
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: #fffefb;
  box-shadow: 0 8px 26px rgb(24 43 33 / 16%);
  color: #26332c;
  cursor: auto;
  font-family: "Avenir Next", Avenir, sans-serif;
  font-size: var(--dictionary-font-size, 12px);
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
}

.dictionary-word:hover .dictionary-tooltip,
.dictionary-word:focus-visible .dictionary-tooltip {
  display: block;
}

.dictionary-tooltip.has-tabs {
  height: min(280px, 50vh);
}

.tooltip-tabs {
  position: sticky;
  top: -12px;
  z-index: 1;
  background: inherit;
}

.dictionary-tooltip.below::before {
  top: -12px;
}

.dictionary-tooltip.docked::before {
  display: none;
}

.dictionary-tooltip::before {
  content: "";
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  height: 12px;
}

.popup-pin {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 1;
  display: inline-flex;
  color: var(--muted-color);
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
}

.popup-pin:hover,
.popup-pin:focus-visible,
.popup-pin[aria-pressed="true"] {
  color: var(--text-color);
  opacity: 1;
  outline: none;
}

.dictionary-tooltip {
  padding-right: 30px;
}

.vocabulary-panel {
  margin-top: 18px;
  padding: 12px;
  border: 2px solid var(--vocab-border);
  border-radius: 10px;
  background: var(--vocab-background);
}

.vocabulary-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.vocabulary-panel.collapsed #vocabulary-bulk-toggle {
  display: none;
}

.vocabulary-bulk {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.vocabulary-bulk-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text-color);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.vocabulary-title {
  margin: 0;
  padding: 2px;
  color: var(--text-color);
  font-size: 15px;
  font-weight: 700;
}

.vocabulary-count {
  color: var(--muted-color);
  font-weight: 400;
}

.vocabulary-panel.collapsed .vocabulary-body {
  display: none;
}

.vocabulary-panel.collapsed .vocabulary-header {
  margin-bottom: 0;
}

.vocabulary-panel.collapsed .vocabulary-toggle-arrow {
  display: inline-block;
  transform: rotate(-90deg);
}

.vocabulary-toggle,
.panel-edit-button:not([hidden]) {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
}

.panel-edit-button {
  color: var(--muted-color);
}

.panel-edit-button:hover,
.panel-edit-button:focus-visible {
  color: var(--text-color);
}

.vocabulary-empty {
  margin: 4px 2px;
  font-size: 14px;
}

.vocabulary-empty[hidden] {
  display: none;
}

.note-panel.collapsed .vocabulary-body {
  display: none;
}

.note-view {
  font-size: 14px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.note-view > :first-child {
  margin-top: 0;
}

.note-view > :last-child {
  margin-bottom: 0;
}

.note-view h3,
.note-view h4,
.note-view h5,
.note-view h6 {
  margin: 12px 0 6px;
  font-family: inherit;
  font-weight: 700;
}

.note-view pre,
.note-view code {
  background: var(--surface-alt);
  border-radius: 4px;
}

.note-view code {
  padding: 1px 4px;
}

.note-view pre {
  overflow-x: auto;
  padding: 8px 10px;
}

.note-view pre code {
  padding: 0;
}

.note-view blockquote {
  margin: 8px 0;
  padding-left: 10px;
  border-left: 3px solid var(--vocab-border);
  color: var(--muted-color);
}

.note-view a {
  color: inherit;
  text-decoration: underline;
}

.note-empty {
  color: var(--muted-color);
}

.note-input {
  box-sizing: border-box;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-alt);
  color: inherit;
  font: inherit;
  font-size: 14px;
  resize: vertical;
}

.note-input[hidden],
.note-view[hidden],
.note-actions [hidden] {
  display: none;
}

.note-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.vocabulary-panel[hidden] {
  display: none;
}

.vocabulary-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  background: transparent;
  scrollbar-width: none;
}

.vocabulary-stack > *,
.vocabulary-scroll-btn {
  pointer-events: auto;
}

.vocabulary-scroll-btn {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 2px 0;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
  font-size: 12px;
  animation: vocab-bounce 1.2s ease-in-out infinite;
}

.vocabulary-scroll-up {
  margin: 0 0 4px;
  animation-name: vocab-bounce-up;
}

.vocabulary-scroll-btn[hidden] {
  display: none;
}

@keyframes vocab-bounce {
  50% {
    transform: translateY(3px);
  }
}

@keyframes vocab-bounce-up {
  50% {
    transform: translateY(-3px);
  }
}

.vocab-header {
  display: block;
  padding-right: 4px;
  cursor: pointer;
  font-weight: 600;
}

.pinned-popup.collapsed > .vocab-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.vocab-label {
  flex: none;
}

.vocab-summary {
  display: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9em;
  font-weight: 400;
  color: inherit;
}

.pinned-popup.collapsed .vocab-summary {
  display: block;
}

.pinned-popup .duplicate-title {
  display: none;
}

.pinned-popup.collapsed {
  height: auto;
  overflow: hidden;
}

.vocabulary-stack .pinned-popup {
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.vocabulary-stack .pinned-popup.collapsed:hover,
.vocabulary-stack .pinned-popup.collapsed:focus-within {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.pinned-popup.collapsed > :not(.popup-pin):not(.vocab-header) {
  display: none;
}

.pinned-popup:not(.collapsed) > .vocab-header {
  margin-bottom: 8px;
}

.dictionary-tooltip.pinned-popup {
  position: relative;
  top: auto;
  right: auto;
  bottom: auto;
  left: auto;
  display: block;
  flex: none;
  transform: none;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  box-shadow: none;
}

.pinned-popup::before {
  display: none;
}

.entry-list {
  display: block;
}

.entry-list[hidden] {
  display: none;
}

.tooltip-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.tooltip-tab {
  padding: 2px 10px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-size: 0.9em;
  opacity: 0.65;
}

.tooltip-tab[aria-selected="true"] {
  background: rgb(127 127 127 / 18%);
  font-weight: 600;
  opacity: 1;
}

.dictionary-entry,
.entry-title {
  display: block;
}

.entry-title {
  margin-bottom: 4px;
  color: #47745b;
  font-weight: 700;
}

.accent-mora {
  display: inline-block;
  padding: 0 1px;
  border: 0 solid currentColor;
}

.accent-high,
.accent-fall {
  border-top-width: 1px;
}

.accent-low,
.accent-rise {
  border-bottom-width: 1px;
}

.accent-fall,
.accent-rise {
  border-right-width: 1px;
}

.entry-definition {
  padding-top: 2px;
}

.entry-definitions {
  display: grid;
  gap: 7px;
}

.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 3px;
}

.entry-tag {
  padding: 1px 5px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--surface-alt);
  color: var(--muted-color);
  font-size: 10px;
  line-height: 1.4;
  white-space: nowrap;
}

.dictionary-tooltip .entry-tag {
  border-color: #52665a;
  background: #405447;
  color: #f3f6f2;
  font-size: 0.83em;
}

.entry-meanings {
  margin: 0;
  padding-left: 22px;
  list-style: decimal;
}

.entry-meanings li {
  padding: 1px 0;
}

.entry-divider {
  display: block;
  height: 1px;
  margin: 8px 0;
  background: var(--border-color);
}

.result-note {
  padding-top: 11px;
  line-height: 1.5;
}

.history-panel {
  min-width: 0;
  margin-top: 0;
  padding: 20px 22px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--surface);
}

.history-heading {
  gap: 12px;
  margin-bottom: 10px;
}

.history-heading h2 {
  font-size: 16px;
}

.history-note {
  font-size: 11px;
}

.search-history {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px 12px;
  padding: 9px 0;
  border-top: 1px solid var(--border-color);
}

.history-text {
  flex: 1 1 100%;
  padding: 0 26px 0 0;
  border: 0;
  background: none;
  color: var(--text-color);
  cursor: pointer;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 15px;
  text-align: left;
  white-space: pre-wrap;
}

.history-text[aria-current="true"] {
  color: #47745b;
  font-weight: 700;
}

.history-text:disabled {
  cursor: wait;
  opacity: 0.6;
}

.history-text:hover,
.history-explaination {
  color: var(--muted-color);
}

.history-text:hover {
  color: #47745b;
  text-decoration: underline;
}

.history-explaination {
  flex: 1 1 auto;
  font-size: 11px;
}

.history-created {
  flex: 1 1 100%;
  color: var(--muted-color);
  font-size: 11px;
}

.note-created {
  margin: -12px 0 14px;
  color: var(--muted-color);
  font-size: 12px;
}

.note-created[hidden] {
  display: none;
}

.history-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 7px;
  right: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted-color);
  cursor: pointer;
  font-size: 11px;
}

.history-delete-icon {
  color: #c62828;
  font-size: 17px;
  font-weight: 700;
  line-height: 0.8;
}

.history-delete:hover:not(:disabled) {
  border-color: #b66b5c;
  color: #a44736;
}

.history-delete:hover:not(:disabled) .history-delete-icon {
  color: #a31515;
}

.history-delete:disabled {
  cursor: wait;
  opacity: 0.6;
}

.side-column {
  display: grid;
  align-content: start;
  align-self: start;
  gap: 24px;
  min-width: 0;
}

.shared-panel.collapsed .shared-body {
  display: none;
}

.shared-panel.collapsed .vocabulary-toggle-arrow {
  display: inline-block;
  transform: rotate(-90deg);
}

.shared-panel.collapsed .history-heading {
  margin-bottom: 0;
}

.shared-panel {
  --shared-row: 38px;
}

.shared-list,
.profile-list,
.comments-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.shared-list {
  max-height: none;
  overflow-y: auto;
  scrollbar-width: none;
}

.shared-empty {
  margin: 0;
  color: var(--muted-color);
  font-size: 13px;
}

.shared-item {
  display: grid;
  grid-template-columns: minmax(0, 88px) minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 8px;
  min-height: var(--shared-row);
  padding: 3px 0;
  box-sizing: border-box;
  border-top: 1px solid var(--border-color);
}

.shared-author,
.shared-title {
  overflow: hidden;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-color);
  cursor: pointer;
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shared-author {
  color: var(--muted-color);
  font-size: 12px;
  font-weight: 700;
}

.shared-title {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 15px;
}

.shared-title:hover,
.shared-author:hover {
  color: #47745b;
  text-decoration: underline;
}

.shared-title[aria-current="true"] {
  color: #47745b;
  font-weight: 700;
}

.shared-date {
  color: var(--muted-color);
  font-size: 11px;
  white-space: nowrap;
}

.vote-button,
.shared-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted-color);
  cursor: pointer;
  font-size: 12px;
  transition: transform 150ms ease, color 150ms ease;
}

.shared-stat {
  cursor: default;
}

.result-vote {
  margin-left: 12px;
}

.result-vote[hidden] {
  display: none;
}

.vote-button:hover {
  transform: translateY(-1px);
  color: #47745b;
}

.vote-button[aria-pressed="true"] {
  border-color: #47745b;
  color: #47745b;
}

.vote-button[aria-pressed="true"] svg {
  fill: currentColor;
}

#shared-sort {
  width: auto;
  height: 24px;
  padding: 2px 6px;
  font-size: 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text-color);
  cursor: pointer;
}

#shared-sort:hover {
  background: var(--surface);
}

.share-button[aria-pressed="true"] {
  border-color: #47745b;
  color: #47745b;
}

.share-button[aria-pressed="true"] .post-icon {
  fill: currentColor;
}

.share-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.share-button[hidden],
#toc-assign-button[hidden],
#clip-text-edit[hidden] {
  display: none;
}

.comments-panel {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

.comments-panel[hidden] {
  display: none;
}

.comments-title {
  margin: 0 0 10px;
  font-size: 15px;
}

.comments-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.comment-meta {
  color: var(--muted-color);
  font-size: 12px;
}

.comment-author {
  color: var(--text-color);
  font-weight: 700;
}

.comment-text {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.comment-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.comment-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-color);
  font: inherit;
  resize: vertical;
}

.profile-dialog {
  width: min(560px, calc(100% - 32px));
}

.profile-summary {
  margin: 0 0 12px;
  color: var(--muted-color);
  font-size: 13px;
}

.profile-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--border-color);
}

.profile-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted-color);
  font-size: 12px;
  white-space: nowrap;
}

.privacy-note {
  margin: 20px 0 0;
  color: #78847d;
  font-size: 12px;
  text-align: center;
}

.privacy-note span {
  padding-right: 5px;
  color: #668771;
}

.status-message {
  min-height: 20px;
  margin: 12px 0 0;
  color: #9a493b;
  font-size: 13px;
  text-align: center;
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100% - 30px, 860px);
    padding-top: 18px;
  }

  .edition-label {
    font-size: 8px;
  }

  .brand {
    font-size: 13px;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-end;
  }

  .help-dialog {
    padding: 16px;
  }

  .help-table {
    min-width: 650px;
  }

  .intro {
    padding-top: 43px;
  }

  .reading-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }

  .workspace {
    position: static;
  }

  #sentence-form,
  .result-panel {
    padding-right: 18px;
    padding-left: 18px;
  }

  .dictionary-tooltip {
    left: 0;
    transform: none;
  }

  .history-panel {
    padding-right: 16px;
    padding-left: 16px;
  }

  .side-column {
    gap: 20px;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-background: #171d1a;
  --text-color: #e4e9e5;
  --surface: #222b26;
  --surface-alt: #1b231f;
  --border-color: #39453e;
  --muted-color: #a0ada4;
  --subtle-color: #bdc8c0;
  --toc-line-color: #8da296;
  --vocab-background: #2b3630;
  --vocab-border: #5d7266;
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(ellipse at 86% 4%, rgb(48 69 56 / 35%), transparent 29rem),
    var(--page-background);
}

:root[data-theme="dark"] .workspace,
:root[data-theme="dark"] .history-panel {
  box-shadow: 0 16px 44px rgb(0 0 0 / 18%);
}

:root[data-theme="dark"] #process-button {
  background: #47745b;
}

:root[data-theme="dark"] .brand-light,
:root[data-theme="dark"] .intro-copy,
:root[data-theme="dark"] .sentence-output {
  color: var(--text-color);
}

:root[data-theme="dark"] .dictionary-word:hover,
:root[data-theme="dark"] .dictionary-word:focus-visible {
  background: #2b3b31;
}

:root[data-theme="dark"] .dictionary-tooltip {
  border-color: #d7cdbb;
  background: #f3ead7;
  color: #26332c;
}

:root[data-theme="dark"] .dictionary-tooltip .entry-title {
  color: #356b4b;
}

:root[data-theme="dark"] .history-text:hover {
  color: #9ac5a5;
}

:root[data-theme="dark"] rt {
  color: #9ac5a5;
}

:root[data-theme="ft"] {
  color-scheme: light;
  --page-background: #fff1e5;
  --text-color: #33302e;
  --surface: #fffaf5;
  --surface-alt: #f8eee4;
  --border-color: #e5d7c9;
  --muted-color: #716761;
  --subtle-color: #5e5650;
  --toc-line-color: #a98b72;
  --vocab-background: #f6e6d6;
  --vocab-border: #c9a98b;
}

:root[data-theme="ft"] body {
  background:
    radial-gradient(ellipse at 86% 4%, rgb(233 209 191 / 42%), transparent 29rem),
    var(--page-background);
}

:root[data-theme="ft"] #process-button {
  background: #990f3d;
}

:root[data-theme="ft"] .dictionary-word:hover,
:root[data-theme="ft"] .dictionary-word:focus-visible {
  background: #f6e2d2;
}

:root[data-theme="ft"] .entry-title,
:root[data-theme="ft"] rt {
  color: #990f3d;
}

:root[data-theme="ft"] .dictionary-tooltip {
  border-color: #d9c7b8;
  background: #fffaf5;
  color: #33302e;
}

:root[data-theme="ft"] .dictionary-tooltip .entry-title {
  color: #990f3d;
}

:root[data-theme="ft"] .dictionary-tooltip .entry-tag {
  border-color: #7d173a;
  background: #990f3d;
  color: #fff8f1;
}

.user-menu {
  position: relative;
}

.user-menu-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.user-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-caret {
  font-size: 11px;
}

.user-menu-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  min-width: 160px;
  flex-direction: column;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgb(0 0 0 / 18%);
}

.user-menu-list[hidden],
.user-menu-item[hidden] {
  display: none;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-color);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.user-menu-item:hover,
.user-menu-item:focus-visible {
  background: var(--surface-alt);
  outline: none;
}

.login-dialog {
  width: min(360px, 90vw);
}

.login-message {
  margin: 0 0 16px;
  color: var(--subtle-color);
  font-size: 14px;
  line-height: 1.5;
}

.login-providers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-provider {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 40px;
  font-size: 14px;
  text-decoration: none;
}

.page-shell > .shared-panel {
  margin-top: 24px;
}

.page-shell:has(> .clipbook-panel:not([hidden])) > .shared-panel {
  display: none;
}

.page-shell > .shared-panel + .clipbook-panel {
  margin-top: 24px;
}

.note-table {
  overflow-x: auto;
  margin: 0.5rem 0;
}

.note-view table {
  border-collapse: collapse;
  width: 100%;
}

.note-view th,
.note-view td {
  border: 1px solid var(--border-color, rgba(128, 128, 128, 0.4));
  padding: 0.3rem 0.6rem;
  text-align: left;
}

.note-view th {
  background: rgba(128, 128, 128, 0.12);
}

.shared-title-text,
.shared-translation {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shared-title rt {
  font-size: 9px;
  font-weight: 400;
}

.shared-translation {
  margin-top: 1px;
  color: var(--muted-color);
  font-family: inherit;
  font-size: 12px;
}

.translation-view {
  white-space: pre-wrap;
}

.clipbook-panel[hidden] {
  display: none;
}

.clipbook-layout {
  position: relative;
  min-height: 300px;
}

.clipbook-toc-viewport {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

.clipbook-tree {
  min-height: 0;
  max-height: 80vh;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 16%);
}

.clipbook-tree.search-active {
  border-color: color-mix(in srgb, var(--toc-line-color) 65%, var(--border-color));
  background: color-mix(in srgb, var(--toc-line-color) 10%, var(--surface));
}

.clipbook-content {
  min-width: 0;
}

.clipbook-content-empty {
  padding: 24px;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  color: var(--muted-color);
  text-align: center;
}

.clipbook-content:has(.result-panel:not([hidden])) .clipbook-content-empty {
  display: none;
}

.clipbook-list.clipbook-children {
  --guide: color-mix(in srgb, var(--text-color) 35%, transparent);
  margin: 0 0 0 16px;
  padding: 0 0 0 28px;
  border-left: 2px solid var(--guide);
}

.clipbook-list.clipbook-children > li {
  position: relative;
}

.clipbook-folder-children {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.2s ease;
}

.clipbook-folder-children.is-open {
  grid-template-rows: 1fr;
}

.clipbook-folder-children > .clipbook-list {
  min-height: 0;
  overflow: hidden;
}

/* Horizontal connector from the vertical guide to each row */
.clipbook-list.clipbook-children > li::before {
  content: "";
  position: absolute;
  top: 18px;
  left: -28px;
  width: 24px;
  border-top: 2px solid var(--guide);
}

/* End the vertical guide at the last row's connector */
.clipbook-list.clipbook-children > li:last-child::after {
  content: "";
  position: absolute;
  top: 19px;
  bottom: 0;
  left: -28px;
  width: 2px;
  background: var(--surface);
}

.clipbook-list.drop-inside {
  outline: 2px dashed var(--toc-line-color);
  outline-offset: -2px;
}

.clipbook-item.drop-inside {
  box-shadow: inset 0 0 0 2px var(--toc-line-color);
}

.clipbook-button {
  padding: 1px 6px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-color);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
}

.clipbook-button:hover {
  transform: translateY(-1px);
  color: var(--toc-line-color);
}

.clipbook-list {
  flex: 1;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  list-style: none;
}

.clipbook-item {
  position: relative;
  display: flex;
  border-radius: 6px;
  border-top: 2px solid transparent;
  border-bottom: 2px solid transparent;
  cursor: grab;
}

.clipbook-item.dragging {
  opacity: 0.4;
}

.clipbook-item.drop-before {
  border-top-color: transparent;
}

.clipbook-item.drop-before::before {
  position: absolute;
  inset: -2px 0 auto;
  z-index: 1;
  border-top: 5px solid var(--toc-line-color);
  content: "";
}

.clipbook-item.drop-after {
  border-bottom-color: transparent;
}

.clipbook-item.drop-after::after {
  position: absolute;
  inset: auto 0 -2px;
  z-index: 1;
  border-bottom: 5px solid var(--toc-line-color);
  content: "";
}

.clipbook-item.selected {
  background: var(--surface-alt);
  font-weight: 700;
}

.clipbook-item-open {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  padding: 6px 8px;
  overflow: hidden;
  border: 0;
  background: none;
  color: var(--text-color);
  cursor: pointer;
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clipbook-item-open:hover {
  color: var(--toc-line-color);
}

.clipbook-folder-expand {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-color);
  cursor: pointer;
}

.clipbook-folder-expand:hover:not(:disabled) {
  background: var(--surface-alt);
  color: var(--toc-line-color);
}

.clipbook-folder-expand:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.clipbook-folder-edit {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-color);
  cursor: pointer;
}

.clipbook-folder-edit:hover,
.clipbook-folder-edit:focus-visible {
  background: var(--surface-alt);
  color: var(--toc-line-color);
}

.clipbook-item-title-input {
  flex: 1;
  min-width: 0;
  margin: 3px 4px 3px 8px;
  padding: 3px 6px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-color);
  font: inherit;
}

.clipbook-item-delete {
  display: none;
  flex: none;
  align-items: center;
  padding: 0 8px;
  border: 0;
  background: none;
  color: var(--muted-color);
  cursor: pointer;
}

.clipbook-item:hover .clipbook-item-delete,
.clipbook-item-delete:focus-visible {
  display: flex;
}

.clipbook-item-delete:hover {
  color: #b3261e;
}

.clipbook-item-delete.blocked {
  opacity: 0.4;
  cursor: not-allowed;
}

.clipbook-count {
  color: var(--muted-color);
  font-size: 11px;
}

.clipbook-empty {
  padding: 8px;
  color: var(--muted-color);
  font-size: 13px;
}

.clipbook-menu {
  position: fixed;
  z-index: 50;
  display: flex;
  flex-direction: column;
  min-width: 130px;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.clipbook-menu-item {
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-color);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  text-align: left;
}

.clipbook-menu-item:hover,
.clipbook-menu-item:focus-visible {
  background: var(--surface-alt);
  color: var(--toc-line-color);
}

.clipbook-menu-separator {
  margin: 4px 0;
  border-top: 1px solid var(--border-color);
}

.clipbook-menu-item.danger {
  color: #b3261e;
}

.clipbook-menu-item.danger:hover,
.clipbook-menu-item.danger:focus-visible {
  color: #b3261e;
}

.clipbook-menu-item.blocked {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Folders vs clips in My Clipbook */
.clipbook-item-open {
  justify-content: flex-start;
}

.clipbook-count {
  margin-left: auto;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-alt);
}

.clipbook-item {
  margin: 4px 0;
  border: 1px solid var(--border-color);
  border-left-width: 4px;
}

.clipbook-item {
  --tone: var(--toc-line-color);
  border-color: color-mix(in srgb, var(--tone) 35%, transparent);
  border-left-color: var(--tone);
  background: color-mix(in srgb, var(--tone) 12%, var(--surface));
}

.clipbook-folder {
  --tone: var(--toc-line-color);
  font-weight: 600;
}

.clipbook-item.clipbook-clip {
  --tone: #3f78a8;
  font-weight: 400;
  background: color-mix(in srgb, var(--tone) 4%, var(--surface));
}

.clipbook-article-icon {
  flex: none;
  color: var(--tone);
}

.clipbook-side button,
.clipbook-menu-item {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.clipbook-side button:not(:disabled):hover,
.clipbook-side button:focus-visible,
.clipbook-menu-item:hover,
.clipbook-menu-item:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 3px 6px rgb(0 0 0 / 14%);
}

.clipbook-item.selected,
.clipbook-clip.selected {
  background: color-mix(in srgb, var(--tone) 30%, var(--surface));
  border-color: var(--tone);
  box-shadow: 0 0 0 1px var(--tone);
  font-weight: 700;
}

.clipbook-item.search-match {
  border-color: var(--toc-line-color);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--toc-line-color) 45%, transparent);
}

.clipbook-item.selected.search-match {
  box-shadow: 0 0 0 2px var(--toc-line-color);
}

.clipbook-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.clipbook-item-add {
  display: inline-flex;
  flex: none;
  align-self: center;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
  margin-right: 4px;
}

.clipbook-root-actions {
  display: flex;
  justify-content: flex-start;
  padding: 2px 4px;
}

.clipbook-root-actions .clipbook-item-add {
  display: inline-flex;
}

.clipbook-root-actions .clipbook-folder-expand {
  flex: 1;
  justify-content: flex-start;
}

.clipbook-panel .history-heading {
  gap: 8px;
  margin-bottom: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}



.clipbook-side {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: visible;
  pointer-events: auto;
  transition: transform 0.25s ease, visibility 0.25s;
}

.clipbook-tree-pane {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

.clipbook-title-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  border: 0;
  background: transparent;
  box-shadow: none;
  font: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.clipbook-collapse-arrow {
  transition: transform 0.2s ease;
  transform-origin: 12px 12px;
  transform: rotate(90deg);
}

.clipbook-title-button[aria-expanded="false"] .clipbook-collapse-arrow {
  transform: none;
}

.clipbook-panel .history-heading > h2 {
  display: flex;
  cursor: pointer;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface-alt);
  box-shadow: 0 4px 12px rgb(0 0 0 / 14%);
}

.clipbook-search-wrap {
  flex: 0 1 420px;
  display: flex;
  align-items: center;
  min-width: 0;
  margin-left: auto;
  gap: 6px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted-color);
}

.clipbook-search-icon {
  flex: none;
}

.clipbook-search {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 0;
  border-radius: 0;
  outline: none;
  background: var(--surface);
  color: var(--text-color);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
}

.clipbook-search::placeholder {
  color: var(--muted-color);
}

.clipbook-search::-webkit-search-cancel-button {
  display: none;
}

.clipbook-search:focus-visible {
  outline: 2px solid var(--toc-line-color);
  outline-offset: -2px;
  border-radius: 4px;
}

.clipbook-search-clear {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted-color);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.clipbook-search-clear:hover,
.clipbook-search-clear:focus-visible {
  background: var(--surface);
  color: var(--text-color);
}

.clipbook-search-clear[hidden] {
  display: none;
}

.clipbook-title-button:hover,
.clipbook-title-button:focus-visible {
  transform: translateY(-2px);
}

.new-clip-dialog {
  width: min(680px, calc(100vw - 32px));
}

.new-clip-dialog #sentence-form {
  padding: 0;
  border: 0;
  box-shadow: none;
}

.new-clip-dialog #clipbook-clip-note-title {
  display: block;
  width: 100%;
  margin-bottom: 16px;
}

.new-clip-dialog #clipbook-clip-note-title[hidden],
.new-clip-dialog label[hidden] {
  display: none;
}

.page-shell > .toc-breadcrumb {
  margin: 16px 0 0;
}

.clipbook-panel > .toc-breadcrumb {
  margin: 8px 0 12px;
}

.clipbook-layout.tree-collapsed .clipbook-side {
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-100%);
}

@media (prefers-reduced-motion: reduce) {
  .clipbook-side,
  .clipbook-side button,
  .clipbook-menu-item {
    transition: none;
  }

  .clipbook-title-button {
    transition: none;
  }

  .clipbook-collapse-arrow {
    transition: none;
  }

  .clipbook-folder-children {
    transition: none;
  }
}

/* My Clipbook: text on the left, vocabulary / translation / notes on the right */
.clip-original-title,
.clip-notion-title {
  display: none;
}

.group-view .clip-body,
.clipbook-content .clip-body {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(240px, 1fr);
  gap: 16px;
  align-items: start;
}

.group-view .clip-aside,
.clipbook-content .clip-aside {
  position: sticky;
  top: 120px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  max-height: calc(100vh - 144px);
  max-height: calc(100dvh - 144px);
  padding-left: 16px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  border-left: 1px solid var(--border-color);
}

.clipbook-content .clip-main {
  min-width: 0;
}

.group-view .clip-original-title,
.group-view .clip-notion-title,
.clipbook-content .clip-original-title,
.clipbook-content .clip-notion-title {
  display: block;
  margin: 0;
  color: var(--subtle-color);
  font-size: 14px;
}

.clipbook-content .clip-aside > .vocabulary-panel {
  flex-shrink: 0;
  margin-top: 0;
}

.clipbook-content .clip-aside .vocabulary-stack {
  max-height: none;
  overflow: visible;
}

@container clipcontent (max-width: 640px) {
  .clipbook-content .clip-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .clipbook-content .clip-aside {
    position: static;
    padding-top: 16px;
    padding-left: 0;
    border-top: 1px solid var(--border-color);
    border-left: 0;
  }
}

.clipbook-content {
  container: clipcontent / inline-size;
}

.group-view .clip-section {
  margin-bottom: 24px;
  padding: 16px;
  border: 1px solid var(--toc-line-color);
  border-radius: 8px;
}

.group-view .clip-section-first {
  border-top: 1px solid var(--toc-line-color);
}

.group-view .clip-section-last {
  border-bottom: 1px solid var(--toc-line-color);
}

.group-view .clip-main {
  min-width: 0;
}

.clip-section-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.clip-section-actions[hidden],
.clip-section form[hidden],
.clip-section .toc-add-button[hidden],
.clip-section .vocabulary-bulk-btn[hidden],
.clip-section .note-actions[hidden] {
  display: none;
}

.insert-clip-button {
  display: block;
  margin: 12px 0 24px;
}

.group-view .clip-aside .vocabulary-panel {
  flex-shrink: 0;
  margin-top: 0;
}

@media (max-width: 700px) {
  .group-view .clip-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .group-view .clip-aside {
    position: static;
    padding-left: 0;
    border-left: 0;
  }
}

/* My Clipbook: panels blend into the clip pane background */
.clipbook-content .result-panel,
.clipbook-content .vocabulary-panel,
.clipbook-content .comments-panel {
  background: transparent;
  border-color: transparent;
}
