﻿:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --bg-soft: #f1f5f9;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --text: #1f2937;
  --muted: #5f6b7a;
  --primary: #1565c0;
  --primary-soft: #e3f2fd;
  --accent: #ff2442;
  --success: #4caf50;
  --success-dark: #1b5e20;
  --border: #e2e8f0;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.06);
  --radius: 18px;
  --max-width: 720px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Nunito Sans", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #f7fbff 0%, #fafafa 40%, #f2f7ff 100%);
  min-height: 100vh;
}

body.no-scroll {
  overflow: hidden;
}

h1,
h2,
.brand-title {
  font-family: "Varela Round", "Nunito Sans", sans-serif;
}

img {
  max-width: 100%;
}

button {
  font-family: inherit;
}

button:focus-visible,
.vocab:focus-visible,
.story-button:focus-visible,
.action-button:focus-visible {
  outline: 3px solid rgba(21, 101, 192, 0.35);
  outline-offset: 2px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.global-header {
  padding: 20px 16px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: var(--max-width);
  margin: 0 auto;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1565c0, #42a5f5);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: var(--shadow-soft);
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
}

.main {
  flex: 1;
  padding: 0 16px 64px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.hero {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 20px 24px;
  box-shadow: var(--shadow);
  max-width: var(--max-width);
  margin: 0 auto 24px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}

.hero p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.6;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.list-section {
  max-width: var(--max-width);
  margin: 0 auto;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.list-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.status-text {
  font-size: 0.85rem;
  color: var(--muted);
}

.ghost-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  min-height: 36px;
}

.ghost-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.count-badge {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  padding: 0 6px;
}

.story-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.story-card {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid transparent;
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
}

.story-card:hover,
.story-card:focus-within {
  transform: translateY(-2px);
  border-color: var(--primary-soft);
  box-shadow: var(--shadow);
}

.story-button {
  width: 100%;
  text-align: left;
  padding: 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: grid;
  gap: 8px;
}

.story-title {
  font-size: 1rem;
  font-weight: 700;
}

.story-meta {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.story-status {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e8f5e9;
  color: var(--success-dark);
}

.story-status.hidden {
  display: none;
}

.reader-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 250, 250, 0.95);
  backdrop-filter: blur(10px);
  padding: 16px 0 12px;
  display: grid;
  gap: 12px;
  max-width: var(--max-width);
  margin: 0 auto;
}

.book-header {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.book-header-info {
  display: grid;
  gap: 4px;
}


.reader-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

.reader-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  position: relative;
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-ui {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #dbe2ea;
  position: relative;
  transition: background 0.2s ease;
}

.toggle-ui::after {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
}

.toggle input:checked + .toggle-ui {
  background: var(--primary);
}

.toggle input:checked + .toggle-ui::after {
  transform: translateX(18px);
}

.toggle-text {
  user-select: none;
}

.reader-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 0 64px;
  font-size: 1.125rem;
  line-height: 1.8;
}

.reader-content p {
  margin: 0 0 18px;
}

.book-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 8px 0 64px;
}

.book-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.book-row {
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 12px 14px;
  display: grid;
  gap: 8px;
  box-shadow: var(--shadow-soft);
}

.book-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.book-word {
  font-size: 1.1rem;
  font-weight: 700;
}

.book-pron {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.book-meaning {
  font-size: 0.95rem;
  color: var(--text);
  background: var(--primary-soft);
  padding: 6px 10px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.book-action {
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
  min-height: 40px;
}

.known-action {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  background: var(--surface-strong);
  color: var(--text);
  white-space: nowrap;
  min-height: 40px;
}

.empty-state {
  margin-top: 20px;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.export-button {
  justify-self: end;
}

.vocab {
  --vocab-bg: var(--primary-soft);
  --vocab-inset: 3px;
  padding: 0 4px;
  border-radius: 6px;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  border: 1px solid transparent;
  display: inline-block;
  position: relative;
  z-index: 0;
  isolation: isolate;
}

.vocab:hover,
.vocab:focus {
  border-color: rgba(21, 101, 192, 0.35);
}

.vocab::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: var(--vocab-inset);
  bottom: var(--vocab-inset);
  background: var(--vocab-bg);
  border-radius: 6px;
  z-index: -1;
}

.vocab.known {
  --vocab-bg: #e8f5e9;
  color: #1b5e20;
}

.vocab.marked-unknown {
  --vocab-bg: #ffebee;
  color: #c62828;
}

.inline-meaning {
  font-size: 0.75em;
  color: #74829a;
  margin-left: 4px;
}

.cloze-input {
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px dashed var(--primary);
  font-size: 0.95rem;
  font-family: inherit;
  min-width: 64px;
}

.cloze-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 36, 66, 0.15);
}

.cloze-input.correct {
  background: #e8f5e9;
  border-color: var(--success);
  color: var(--success-dark);
}

.cloze-input.incorrect {
  background: #ffebee;
  border-color: #ef5350;
  animation: shake 0.3s;
}

.reader-loading {
  display: none;
  max-width: var(--max-width);
  margin: 32px auto;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 12px;
  color: var(--muted);
  box-shadow: var(--shadow-soft);
}

.reader-loading.is-active {
  display: block;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sheet,
.popover {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  z-index: 50;
}

.sheet {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 20px;
  max-width: var(--max-width);
  margin: 0 auto;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  transform: translateY(120%);
  transition: transform 0.3s ease;
  padding: 16px 18px;
}

.sheet.active {
  transform: translateY(0);
}

.popover {
  position: fixed;
  width: 320px;
  padding: 16px;
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.popover.active {
  opacity: 1;
  transform: scale(1);
}

.word-card {
  display: grid;
  gap: 12px;
  position: relative;
}

.card-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: none;
  background: #ef4444;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.word-card .card-close {
  background-color: #ef4444;
  color: #fff;
}

.card-close svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.word-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding-right: 40px;
  margin-bottom: 8px;
}

.word-header .icon-button {
  margin-left: 10px;
}

.word-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.word-pron {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
}

.word-pron span {
  background: #eef2f7;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
}

.word-meaning {
  background: var(--primary-soft);
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--primary);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.word-type {
  background: rgba(21, 101, 192, 0.12);
  color: var(--primary);
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.word-sentences {
  font-size: 0.9rem;
  color: var(--muted);
  display: grid;
  gap: 6px;
  background: var(--primary-soft);
  padding: 10px 12px;
  border-radius: 12px;
}

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

.action-button {
  border: none;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  min-height: 44px;
}

.action-button.primary {
  background: var(--success);
  color: #fff;
  box-shadow: 0 10px 20px rgba(76, 175, 80, 0.2);
}

.action-button.secondary {
  background: var(--accent);
  color: #fff;
  border: none;
  box-shadow: 0 10px 20px rgba(255, 36, 66, 0.2);
}

.action-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.action-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.action-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.hidden {
  display: none;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

@media (min-width: 768px) {
  :root {
    --max-width: 600px;
  }

  .main {
    padding: 0 24px 80px;
  }

  .hero {
    padding: 28px 32px 32px;
  }

  .reader-content {
    font-size: 1.15rem;
  }

  .word-actions {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }
}

@media (min-width: 1024px) {
  :root {
    --max-width: 700px;
  }

  .reader-content {
    max-width: 700px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --surface: #111827;
    --surface-strong: #1f2937;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2937;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
    --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.35);
  }

  body {
    background: radial-gradient(circle at top, #111827 0%, #0f172a 50%, #0b1120 100%);
  }

  .reader-header {
    background: rgba(15, 23, 42, 0.9);
  }

  .toggle-ui {
    background: #334155;
  }

  .inline-meaning {
    color: #94a3b8;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
