/* Notebook theme — phase 1 shell + existing app components */

:root {
  --blue: #2563eb;
  --yellow: #facc15;
  --yellow-dark: #eab308;
  --orange: #ea580c;
  --paper: #fffefb;
  --ink: #111827;
  --muted: #6b7280;
  --danger: #dc2626;
  --card: #ffffff;
  --border: #e5e7eb;
  --bubble: #fafafa;
  --accent: var(--blue);
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --ok: #16a34a;
  --shadow: rgba(15, 23, 42, 0.06);
  --reading-font: "Times New Roman", "Noto Serif JP", "Noto Serif", "Songti SC", "STSong", Georgia,
    "Times", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans", sans-serif;
  background: linear-gradient(180deg, #fff, #fffbeb 80%);
  line-height: 1.55;
  font-size: 15px;
}

body.dark-mode {
  --paper: #1f2937;
  --ink: #f9fafb;
  --muted: #d1d5db;
  --card: #111827;
  --border: #374151;
  --bubble: #1f2937;
  --accent-soft: #1e3a5f;
  background: linear-gradient(180deg, #0f172a, #111827 80%);
}

.hidden {
  display: none !important;
}

/* ── Top bar ── */
.topbar {
  max-width: 1180px;
  margin: 10px auto 0;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-spacer,
.top-actions {
  width: 180px;
  flex-shrink: 0;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-title {
  margin: 0;
  color: #0b74cf;
  font-size: clamp(1.25rem, 3.5vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  font-family: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", "游明朝", "MS PMincho",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "游ゴシック", "Noto Sans JP", Meiryo,
    sans-serif;
  text-align: center;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px;
}

.icon-btn:hover {
  opacity: 0.8;
}

.lang-bar {
  display: flex;
  gap: 4px;
}

.lang-bar button {
  border: 2px solid #bfdbfe;
  background: #eff6ff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--blue);
  font-weight: 600;
}

.lang-bar button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.zoom-bar {
  display: flex;
  align-items: center;
  gap: 2px;
}

.zoom-bar button {
  border: 2px solid #bfdbfe;
  background: #eff6ff;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--blue);
  min-width: 2em;
}

#zoomLabel {
  min-width: 2.8rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}

/* ── Page wrap ── */
.page-wrap {
  padding: 10px 20px 36px;
  max-width: 1180px;
  margin: 0 auto;
}

.filter-switcher {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.filter-switcher button {
  min-width: 72px;
  border: 2px solid #bfdbfe;
  border-radius: 999px;
  padding: 9px 20px;
  background: #eff6ff;
  color: var(--blue);
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.12);
}

.filter-switcher button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

/* ── Notebook shell ── */
.notebook {
  position: relative;
  border: 3px solid var(--yellow-dark);
  background: var(--yellow);
  border-radius: 30px 14px 24px 16px / 14px 30px 12px 32px;
  padding: 10px 18px 14px;
  min-height: 640px;
}

.rings {
  position: absolute;
  top: 48px;
  bottom: 48px;
  left: -8px;
  width: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  z-index: 4;
  pointer-events: none;
}

.rings span {
  width: 26px;
  height: 38px;
  border: 4px solid #374151;
  border-left-color: transparent;
  border-radius: 999px;
  transform: rotate(-45deg);
}

.paper {
  position: relative;
  min-height: 610px;
  background: var(--paper);
  border: 3px solid var(--yellow-dark);
  border-radius: 28px 12px 20px 16px / 12px 28px 10px 30px;
  padding: 18px 20px 20px 56px;
  overflow: hidden;
}

.notebook-tabs {
  position: absolute;
  right: -50px;
  top: 105px;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notebook-tabs .tab {
  width: 66px;
  height: 118px;
  border: 0;
  color: #fff;
  background: #fb923c;
  border-radius: 0 12px 12px 0;
  clip-path: polygon(18% 0, 100% 0, 100% 100%, 18% 100%, 0 50%);
  writing-mode: vertical-rl;
  letter-spacing: 0.2em;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.notebook-tabs .tab.active {
  background: var(--orange);
}

.content-page {
  display: none;
}

.content-page.active {
  display: block;
}

/* ── Rule footer ── */
.rule-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.rule-footer-rules {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.rule-footer-long {
  color: var(--danger);
}

.rule-footer-other {
  color: var(--blue);
}

/* ── Home toolbar ── */
.home-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dashed #fde68a;
}

.search-wrap {
  position: relative;
  flex: 1 1 180px;
  max-width: 100%;
}

.search-wrap input[type="text"],
.search-wrap input[type="search"] {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #bfdbfe;
  border-radius: 999px;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--ink);
}

.search-wrap.is-learn-filter input[type="text"],
.search-wrap.is-learn-filter input[type="search"] {
  border-color: var(--blue);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.15);
}

.learn-filter-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

.search-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 220px;
  overflow-y: auto;
  background: var(--card);
  border: 2px solid var(--yellow-dark);
  border-radius: 12px;
  box-shadow: 0 8px 24px var(--shadow);
  z-index: 200;
}

.search-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--ink);
}

.search-item:hover {
  background: var(--accent-soft);
}

.search-item.is-active,
.search-item.is-active:hover {
  background: var(--blue);
  color: #fff;
}

.search-item.is-active small {
  color: rgba(255, 255, 255, 0.88);
}

.search-more {
  margin: 0;
  padding: 8px 12px;
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
  border-top: 1px dashed var(--border);
  background: var(--bubble);
}

.search-item small {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 2px;
}

.btn-fav {
  font-size: 1.2rem;
  line-height: 1;
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--yellow-dark);
  background: #fff7d6;
  cursor: pointer;
}

.btn-fav.is-on {
  color: #b45309;
  border-color: #fbbf24;
  background: #fffbeb;
}

.sub {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0;
}

.view-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin: 0 0 12px;
  color: var(--blue);
}

/* ── Progress bar ── */
.progress-dashes {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 6px;
  margin: 2px 0 18px;
}

.progress-dashes span {
  display: block;
  height: 3px;
  border-radius: 99px;
  background: #fff;
  border: 1px solid #fde68a;
}

.progress-dashes span.active {
  background: var(--yellow-dark);
  border-color: var(--yellow-dark);
}

body.dark-mode .progress-dashes span {
  background: var(--card);
  border-color: #4b5563;
}

body.dark-mode .progress-dashes span.active {
  background: var(--yellow-dark);
  border-color: var(--yellow-dark);
}

/* ── Home collapsible panels ── */
.home-panel {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px dashed #fde68a;
  border-radius: 12px;
  background: color-mix(in srgb, var(--paper) 96%, #fef3c7);
}

body.dark-mode .home-panel {
  background: color-mix(in srgb, var(--paper) 92%, #374151);
  border-color: #4b5563;
}

.home-panel summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.home-panel summary::-webkit-details-marker {
  display: none;
}

.home-panel summary::before {
  content: "▸";
  font-size: 0.75rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.home-panel[open] summary::before {
  transform: rotate(90deg);
}

.home-panel .rel-list {
  margin-top: 8px;
}

/* ── Learn layout (4-corner bubbles) ── */
.learn-stage {
  position: relative;
  margin-bottom: 4px;
}

.learn-pool-counter {
  margin: 0 0 8px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.round-celebrate {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.round-celebrate.is-active {
  opacity: 1;
}

.round-celebrate-card {
  position: relative;
  min-width: min(92%, 320px);
  padding: 28px 22px 24px;
  border: 3px solid var(--yellow-dark);
  border-radius: 28px;
  background: linear-gradient(165deg, #fffbeb 0%, #ffffff 55%, #eff6ff 100%);
  box-shadow: 0 18px 40px rgba(234, 179, 8, 0.28);
  text-align: center;
  transform: scale(0.72) translateY(16px);
  opacity: 0;
}

.round-celebrate.is-active .round-celebrate-card {
  animation: roundCelebratePop 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.round-celebrate-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 8px;
  animation: roundCelebrateWiggle 0.9s ease-in-out 0.2s 2;
}

.round-celebrate-title {
  margin: 0 0 8px;
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--orange);
  letter-spacing: 0.04em;
}

.round-celebrate-sub {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.45;
}

.round-celebrate-confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.round-confetti-piece {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 8px;
  opacity: 0;
  animation-name: roundConfettiFall;
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
}

.round-confetti-piece[data-shape="circle"] {
  border-radius: 999px;
}

.round-confetti-piece[data-shape="ribbon"] {
  width: 6px;
  height: 14px;
  border-radius: 2px;
}

@keyframes roundCelebratePop {
  0% {
    transform: scale(0.72) translateY(16px);
    opacity: 0;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

@keyframes roundCelebrateWiggle {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  25% {
    transform: rotate(-12deg) scale(1.08);
  }
  75% {
    transform: rotate(12deg) scale(1.08);
  }
}

@keyframes roundConfettiFall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translateY(220px) rotate(540deg);
  }
}

body.dark-mode .round-celebrate-card {
  background: linear-gradient(165deg, #422006 0%, #1f2937 55%, #1e3a5f 100%);
}

.classify-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.classify-word-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 2px solid var(--yellow-dark);
  border-radius: 999px;
  background: #fff7d6;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(234, 179, 8, 0.15);
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.classify-word-btn:hover {
  transform: translateY(-2px) scale(1.03);
}

.classify-word-btn.classify-syn.is-on {
  background: #dbeafe;
  border-color: var(--blue);
  color: var(--blue);
}

.classify-word-btn.classify-ant.is-on {
  background: #fee2e2;
  border-color: var(--danger);
  color: var(--danger);
}

.learn-layout {
  position: relative;
  min-height: 400px;
  height: 420px;
}

.bubble {
  border: 3px solid var(--yellow-dark);
  border-radius: 999px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: inherit;
  font: inherit;
}

button.bubble {
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

button.bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(234, 179, 8, 0.18);
}

.bubble-main,
.main-bubble {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(400px, 86%);
  min-height: 250px;
  max-height: 320px;
  padding: 16px 18px;
  transform: translate(-50%, -50%);
  z-index: 3;
  box-shadow: 0 8px 20px rgba(234, 179, 8, 0.18);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
}

.bubble-side,
.mini.bubble-side {
  position: absolute;
  width: min(210px, 30%);
  min-height: 110px;
  height: auto;
  max-height: 130px;
  padding: 10px 8px;
  z-index: 2;
}

.bubble-side.left-top {
  top: 28px;
  left: 16px;
}

.bubble-side.left-bottom {
  bottom: 28px;
  left: 16px;
}

.bubble-side.right-top {
  top: 28px;
  right: 16px;
}

.bubble-side.right-bottom {
  bottom: 28px;
  right: 16px;
}

.main-char {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}

.mini-char {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 2px;
}

.mini-char-hv {
  font-size: 0.68rem;
}

.mini-char-on {
  font-size: 0.62rem;
}

.main-char-hv {
  font-size: 0.88rem;
}

.main-char-on {
  font-size: 0.78rem;
}

.main-chars {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 16px;
  width: 100%;
}

.main-char-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 0 1 auto;
  min-width: 2.8rem;
}

.main-char-hv {
  color: var(--muted);
  margin-bottom: 4px;
  line-height: 1.3;
  font-family: var(--reading-font);
}

.main-char-col.side-left .main-char-hv {
  color: #dc2626;
  font-weight: 600;
}
.main-char-col.side-right .main-char-hv {
  color: #2563eb;
  font-weight: 600;
}
.main-char-col.side-rule .main-char-hv {
  color: var(--blue);
  font-weight: 600;
}

.main-char-on {
  color: var(--muted);
  line-height: 1.25;
  letter-spacing: 0.04em;
  font-family: var(--reading-font);
}

.main-char-col.side-left .main-char-on {
  color: #dc2626;
  font-weight: 600;
}
.main-char-col.side-right .main-char-on {
  color: #2563eb;
  font-weight: 600;
}
.main-char-col.side-rule .main-char-on {
  color: var(--blue);
  font-weight: 600;
}

.main-rules {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding-top: 4px;
}

.main-rule-line {
  font-size: 0.72rem;
  color: var(--blue);
  line-height: 1.45;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.main-rule-line.side-left {
  color: #dc2626;
  font-weight: 600;
}
.main-rule-line.side-right {
  color: #2563eb;
  font-weight: 600;
}
.main-rule-line.side-rule {
  color: var(--blue);
  font-weight: 600;
}

.mini-chars {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.mini-char-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 0 1 auto;
  min-width: 0;
}

.mini-char-hv {
  color: var(--muted);
  margin-bottom: 2px;
  line-height: 1.2;
  word-break: break-word;
  font-family: var(--reading-font);
}

.mini-char-col.side-left .mini-char-hv {
  color: #dc2626;
  font-weight: 600;
}
.mini-char-col.side-right .mini-char-hv {
  color: #2563eb;
  font-weight: 600;
}
.mini-char-col.side-rule .mini-char-hv {
  color: var(--blue);
  font-weight: 600;
}

.mini-char-on {
  color: var(--muted);
  line-height: 1.2;
  letter-spacing: 0.03em;
  word-break: keep-all;
  font-family: var(--reading-font);
}

.mini-char-col.side-left .mini-char-on {
  color: #dc2626;
  font-weight: 600;
}
.mini-char-col.side-right .mini-char-on {
  color: #2563eb;
  font-weight: 600;
}
.mini-char-col.side-rule .mini-char-on {
  color: var(--blue);
  font-weight: 600;
}

.main-hv {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 4px;
  font-family: var(--reading-font);
}
.main-word {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.viz-legend {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
}

.out {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px dashed #fde68a;
  background: var(--bubble);
  min-height: 44px;
  font-size: 0.92rem;
}

.out.interactive-flash {
  animation: fout 0.28s ease;
}

@keyframes fout {
  from {
    opacity: 0.55;
  }
  to {
    opacity: 1;
  }
}

.home-extra {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed #fde68a;
}

.section-title,
.rel-head {
  font-size: 0.86rem;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--muted);
}

.rel-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
  padding: 2px;
}

.rel-pill {
  border: 2px solid #bfdbfe;
  background: #eff6ff;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--ink);
}

.rel-pill:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.count-badge {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: normal;
}

.meta-line {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 12px 0 0;
  text-align: center;
}

/* ── Dock nav (inside paper) ── */
.dock-nav {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px solid #fde68a;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dock-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 12px;
  width: 100%;
}

.dock-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dock-cluster.dock-center {
  flex: 1 1 auto;
  justify-content: center;
  flex-wrap: nowrap;
}

.dock-auto {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.dock-auto input {
  margin: 0;
  cursor: pointer;
}

.dock-hint {
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  max-width: 520px;
}

button,
.btnlike {
  border: 2px solid #bfdbfe;
  background: #eff6ff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--blue);
  font-family: inherit;
  font-weight: 600;
}

button:hover:not(:disabled) {
  filter: brightness(1.03);
}

button.primary,
.dock-row .dock-main {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
  font-weight: 700;
  min-width: 11em;
}

button.primary:hover:not(:disabled),
.dock-row .dock-main:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-tts {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: auto;
  padding: 8px 12px;
}

.btn-tts-icon {
  flex-shrink: 0;
  display: block;
}

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

/* ── Quiz ── */
.quiz-wrap {
  padding: 4px 8px 0;
  max-width: 640px;
  margin: 0 auto;
}

.quiz-head {
  margin-bottom: 8px;
}

.quiz-mode-switcher {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.quiz-mode-switcher button {
  min-width: 0;
  border: 2px solid #bfdbfe;
  border-radius: 999px;
  padding: 8px 14px;
  background: #eff6ff;
  color: var(--blue);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.1);
}

.quiz-mode-switcher button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.quiz-head .view-title {
  margin-bottom: 4px;
}

.quiz-head .sub {
  margin: 0;
}

.quiz-hv {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
  padding: 20px 16px;
  background: var(--bubble);
  border: 3px solid var(--yellow-dark);
  border-radius: 999px;
  margin-bottom: 14px;
  letter-spacing: 0.04em;
  font-family: var(--reading-font);
}

.quiz-hv.quiz-prompt-word {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  font-family: inherit;
}

.quiz-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.quiz-toolbar label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}

.quiz-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.quiz-opt {
  padding: 16px 12px;
  font-size: 1.35rem;
  font-weight: 700;
  border-radius: 12px;
  border: 2px solid #bfdbfe;
  background: #eff6ff;
  cursor: pointer;
  min-height: 64px;
  color: var(--ink);
}

.quiz-opt-reading {
  font-family: var(--reading-font);
  font-size: 1.2rem;
  letter-spacing: 0.04em;
}

.quiz-opt:hover:not(:disabled) {
  border-color: var(--blue);
}

.quiz-opt.correct {
  border-color: var(--ok);
  background: #dcfce7;
  color: var(--ok);
}

.quiz-opt.wrong {
  border-color: var(--danger);
  background: #fee2e2;
}

.quiz-opt:disabled {
  cursor: default;
  opacity: 1;
}

.quiz-feedback {
  min-height: 1.5em;
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.quiz-feedback.ok {
  color: var(--ok);
  font-weight: 600;
}

.quiz-feedback.bad {
  color: #b91c1c;
}

/* ── Add form ── */
.add-wrap {
  padding: 4px 4px 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.add-box {
  background: color-mix(in srgb, var(--card) 82%, #e5e7eb);
  border: 2px dashed #9ca3af;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

body.dark-mode .add-box {
  background: color-mix(in srgb, var(--card) 90%, #374151);
  border-color: #4b5563;
}

.add-inputs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px 12px;
  align-items: center;
}

.add-inputs label {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

.add-inputs input {
  width: 100%;
  padding: 10px;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--card);
}

.add-box-notes label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 4px;
}

.add-box-notes label:not(:first-child) {
  margin-top: 12px;
}

.add-box-notes textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border: 1px solid #9ca3af;
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--card);
}

.word-table-wrap {
  flex: 1;
  min-height: 0;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 10px;
  background: var(--bubble);
}

.form-stack label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

.form-stack label:first-of-type {
  margin-top: 0;
}

.form-stack input[type="text"],
.form-stack textarea {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #d1d5db;
  border-radius: 10px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}

.form-stack textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.5;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  align-items: center;
}

.bottom-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed #fde68a;
}

.bottom-links button {
  font-size: 0.82rem;
}

.lib-custom,
.lib-all-list {
  max-height: 120px;
}

details.lib-all summary {
  cursor: pointer;
  font-weight: 600;
  margin: 10px 0 6px;
  color: var(--muted);
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .bubble-main,
  .main-bubble {
    width: min(340px, 82%);
    min-height: 220px;
  }

  .bubble-side,
  .mini.bubble-side {
    width: min(180px, 28%);
  }

  .main-char {
    font-size: 1.85rem;
  }

  .mini-char {
    font-size: 1.2rem;
  }
}

@media (max-width: 900px) {
  .notebook-tabs {
    position: static;
    flex-direction: row;
    justify-content: center;
    margin-top: 10px;
    gap: 6px;
  }

  .notebook-tabs .tab {
    width: auto;
    height: auto;
    min-width: 72px;
    padding: 8px 14px;
    border-radius: 999px;
    clip-path: none;
    writing-mode: horizontal-tb;
    letter-spacing: 0;
    font-size: 15px;
  }

  .notebook {
    padding-bottom: 8px;
  }
}

@media (max-width: 760px) {
  .topbar-spacer {
    display: none;
  }

  .top-actions {
    width: auto;
  }

  .rings {
    display: none;
  }

  .paper {
    padding: 14px 12px 16px;
    min-height: 520px;
  }

  .page-wrap {
    padding: 6px 8px 20px;
  }

  .learn-layout {
    min-height: 340px;
    height: 360px;
  }

  .bubble-main,
  .main-bubble {
    width: min(240px, 72%);
    min-height: 190px;
    top: 46%;
  }

  .bubble-side,
  .mini.bubble-side {
    width: min(128px, 38%);
    min-height: 78px;
    max-height: 96px;
    padding: 8px 6px;
  }

  .bubble-side.left-top {
    top: 4px;
    left: 0;
  }

  .bubble-side.left-bottom {
    bottom: 56px;
    left: 0;
  }

  .bubble-side.right-top {
    top: 4px;
    right: 0;
  }

  .bubble-side.right-bottom {
    bottom: 56px;
    right: 0;
  }

  .main-char {
    font-size: 1.65rem;
  }

  .mini-char {
    font-size: 1rem;
  }

  .mini-char-hv {
    font-size: 0.58rem;
  }

  .mini-char-on {
    font-size: 0.52rem;
  }

  .quiz-grid {
    grid-template-columns: 1fr;
  }

  .add-inputs {
    grid-template-columns: 1fr 1fr;
  }

  .add-inputs label {
    grid-column: span 2;
  }

  .rule-footer {
    font-size: 12px;
  }
}
