:root {
  --bg: #f5e6c8;
  --bg-soft: #f9eed8;
  --panel: #fff7e8;
  --ink: #3d3326;
  --muted: #6e6356;
  --green: #5b8731;
  --accent-light: #a4cf72;
  --brown: #8b6914;
  --blue: #55ffff;
  --purple: #9955ff;
  --mic: #22d3ee;
  --line: #d8c6a4;
  --danger: #b64848;
  --shadow: 0 10px 25px rgba(61, 51, 38, 0.12);
  font-family: Arial, Helvetica, sans-serif;
}

body[data-theme="magic"] {
  --bg: #f3e8ff;
  --bg-soft: #fdf2f8;
  --panel: #ffffff;
  --ink: #4c1d95;
  --muted: #7e6997;
  --green: #a855f7;
  --accent-light: #ec4899;
  --brown: #ec4899;
  --mic: #ec4899;
  --line: #e9d5ff;
  --shadow: 0 10px 25px rgba(124, 58, 237, 0.18);
}

body[data-theme="ocean"] {
  --bg: #dbeafe;
  --bg-soft: #ecfeff;
  --panel: #ffffff;
  --ink: #0c4a6e;
  --muted: #5a7891;
  --green: #0284c7;
  --accent-light: #06b6d4;
  --brown: #0e7490;
  --mic: #fb923c;
  --line: #bae6fd;
  --shadow: 0 10px 25px rgba(2, 132, 199, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg-soft) 0%, var(--bg) 100%);
  color: var(--ink);
  min-height: 100vh;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.hidden {
  display: none !important;
}

.card {
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.hero-card,
.result-card {
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0 0 8px;
}

.title-text,
.muted {
  color: var(--muted);
}

.status-row,
.screen-header,
.input-row,
.progress-meta,
.checkbox-row,
.quick-books {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-row,
.screen-header {
  margin-bottom: 14px;
  justify-content: flex-start;
  gap: 12px;
}

.screen-header h2 {
  margin: 0;
}

.saved-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #e7f7df;
  color: var(--green);
  font-size: 0.92rem;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 18px 0;
}

.stat-box {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 10px;
}

.stat-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.progress-group {
  margin: 16px 0;
}

.progress-bar {
  height: 16px;
  border-radius: 999px;
  overflow: hidden;
  background: #ead9ba;
}

.progress-bar-secondary {
  background: #e3d7f4;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--accent-light));
  transition: width 0.25s ease;
}

.home-actions {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.field {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.field span {
  font-weight: 700;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fffdf7;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.button {
  border: 0;
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 700;
}

.button-primary {
  background: var(--green);
  color: #fff;
}

.button-secondary {
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
}

.button-ghost {
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--line);
}

.button-small {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
}

.button-large {
  width: 100%;
  padding: 16px 20px;
  font-size: 1.05rem;
}

.button-icon {
  min-width: 74px;
}

.mic-button {
  padding: 18px 20px;
  background: var(--mic);
  color: #fff;
}

.emoji-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.emoji-button {
  min-height: 58px;
  font-size: 1.4rem;
  background: #fff;
  border: 2px solid var(--line);
}

.emoji-button.selected {
  transform: translateY(-2px) scale(1.03);
  border-color: var(--green);
  background: #eef9e9;
}

.recent-books {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-row {
  justify-content: flex-start;
  margin: 16px 0;
}

.checkbox-row input {
  width: auto;
}

.result-card h2 {
  font-size: 2.2rem;
  color: var(--green);
}

.field-hint {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

.levelup-banner {
  margin: 0 0 18px;
  padding: 18px 16px;
  border-radius: 18px;
  background: linear-gradient(135deg, #fff3b0, #ffd86b);
  color: var(--ink);
  text-align: center;
  border: 3px solid #f0b90b;
  box-shadow: 0 6px 22px rgba(240, 185, 11, 0.35);
  animation: levelup-pop 0.6s ease;
}

.levelup-eyebrow {
  margin: 0 0 4px;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #8a5a00;
}

.levelup-banner h3 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
}

@keyframes levelup-pop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  60% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

.danger-zone {
  margin-top: 28px;
  padding: 16px;
  border: 2px dashed var(--danger);
  border-radius: 16px;
  background: #fff5f5;
}

.danger-zone-title {
  margin: 0 0 4px;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.danger-zone-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.button-danger {
  background: #fff;
  color: var(--danger);
  border: 2px solid var(--danger);
}

.button-danger:hover {
  background: var(--danger);
  color: #fff;
}

.section-heading {
  margin: 22px 0 10px;
  font-size: 1rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
  width: 24px;
  height: 24px;
  color: currentColor;
}

.icon-sm {
  width: 18px;
  height: 18px;
}

.icon-md {
  width: 24px;
  height: 24px;
}

.icon-lg {
  width: 44px;
  height: 44px;
}

.icon-xl {
  width: 64px;
  height: 64px;
}

.button-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.button-icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  flex-shrink: 0;
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 12px;
  border-radius: 18px;
  border: 3px solid transparent;
  cursor: pointer;
  font: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease,
    background 0.15s ease;
  text-align: center;
  width: 100%;
}

.action-card:hover {
  transform: translateY(-2px);
}

.action-card-primary {
  background: var(--green);
  color: #fff;
  padding: 24px 16px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.action-card-primary:hover {
  background: var(--green);
  filter: brightness(1.05);
}

.action-card-secondary {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

.action-card-secondary:hover {
  border-color: var(--green);
  color: var(--green);
}

.action-card-label {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.action-card-primary .action-card-label {
  font-size: 1.05rem;
}

.home-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mic-icon-button {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--mic);
  color: #fff;
  border: none;
}

.mic-icon-button:hover {
  filter: brightness(1.05);
}

.mic-button.recording,
.mic-icon-button.recording {
  position: relative;
}

.mic-button.recording::after,
.mic-icon-button.recording::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 3px solid var(--mic);
  pointer-events: none;
  animation: mic-pulse 1.1s infinite ease-out;
}

@keyframes mic-pulse {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.4);
    opacity: 0;
  }
}

.theme-field {
  margin: 0;
  padding: 0;
  border: none;
}

.theme-field legend {
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.theme-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  background: #ffffff;
  border: 3px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease, background 0.15s ease;
  user-select: none;
}

.theme-card:hover {
  transform: translateY(-2px);
}

.theme-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-card.selected {
  border-color: var(--green);
  background: linear-gradient(180deg, #ffffff, var(--bg-soft));
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
}

.theme-card-illustration {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-card-illustration svg {
  width: 100%;
  height: 100%;
}

.theme-card-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.book-list {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.book-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 14px;
}

.book-card-finished {
  border-color: var(--green);
  background: #f5fbef;
}

.book-card-main {
  flex: 1;
  min-width: 0;
}

.book-card-title {
  margin: 0 0 4px;
  font-size: 1rem;
  word-break: break-word;
}

.book-card-meta,
.book-card-dates {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.book-card-dates {
  margin-top: 2px;
  font-size: 0.78rem;
}

.book-card-badge {
  flex-shrink: 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0 4px;
}

.stats-summary .stat-box strong {
  font-size: 1rem;
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: end;
  height: 160px;
  padding: 8px 4px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 14px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  min-width: 0;
}

.bar-value {
  font-size: 0.7rem;
  color: var(--muted);
  height: 14px;
}

.bar-track {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  background: #f3e8d2;
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  background: linear-gradient(180deg, var(--green), var(--accent-light));
  border-radius: 6px;
  transition: height 0.35s ease;
}

.bar-label {
  font-size: 0.72rem;
  color: var(--muted);
}

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

.recent-log {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
}

.recent-log-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.recent-log-left strong {
  font-size: 0.95rem;
  word-break: break-word;
}

.recent-log-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.recent-log-xp {
  flex-shrink: 0;
  color: var(--green);
  font-weight: 700;
}

.recent-log-empty {
  list-style: none;
  padding: 10px 0;
  text-align: center;
}

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .emoji-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .theme-card-illustration {
    width: 48px;
    height: 48px;
  }

  .theme-card-name {
    font-size: 0.75rem;
  }

  .status-row,
  .input-row,
  .quick-books {
    flex-direction: column;
    align-items: stretch;
  }
}
