:root {
  --bg: #f7efe0;
  --bg-deep: #e8d7bf;
  --ink: #2c241b;
  --ink-soft: #665747;
  --accent: #cb5528;
  --accent-2: #2f7a6b;
  --accent-3: #e7ab3b;
  --panel: rgba(255, 253, 248, 0.86);
  --border: rgba(44, 36, 27, 0.14);
  --shadow: 0 24px 60px rgba(44, 36, 27, 0.16);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Manrope", "Segoe UI", sans-serif;
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% 10%, rgba(203, 85, 40, 0.25), transparent 34%),
    radial-gradient(circle at 84% 8%, rgba(47, 122, 107, 0.24), transparent 36%),
    radial-gradient(circle at 76% 72%, rgba(231, 171, 59, 0.22), transparent 38%),
    linear-gradient(170deg, #fff8ec 0%, var(--bg) 46%, var(--bg-deep) 100%);
  line-height: 1.45;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(44, 36, 27, 0.08) 0.8px, transparent 0);
  background-size: 24px 24px;
  opacity: 0.45;
  z-index: -1;
}

.app {
  width: min(1180px, 100% - 32px);
  margin: 28px auto 42px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(34px, 5vw, 48px);
  line-height: 1.06;
  font-weight: 700;
}

.subtitle {
  margin: 10px 0 0;
  color: var(--ink-soft);
  max-width: 640px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 10px;
  align-self: center;
}

.stat {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.72);
  text-align: center;
}

.stat span {
  display: block;
  font-size: clamp(24px, 4vw, 30px);
  font-weight: 800;
  color: var(--accent);
}

.stat label {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(340px, 1.1fr);
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.panel.wide {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.panel h2 {
  margin: 0;
  font-size: 22px;
  font-family: "Fraunces", Georgia, serif;
}

.helper {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 14px;
}

textarea {
  width: 100%;
  min-height: 165px;
  resize: vertical;
}

textarea,
input,
select {
  border: 1px solid rgba(44, 36, 27, 0.18);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  font: inherit;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(47, 122, 107, 0.16);
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.row.wrap {
  margin-top: 10px;
  flex-wrap: wrap;
}

.parse-actions {
  justify-content: flex-end;
}

.lexical-panel,
.history-panel {
  border: 0;
  background: transparent;
  position: relative;
}

.lexical-panel>summary,
.history-panel>summary {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-family: "Fraunces", Georgia, serif;
  font-size: 22px;
  font-weight: 700;
  padding-right: 140px;
}

.lexical-panel>summary::-webkit-details-marker,
.history-panel>summary::-webkit-details-marker {
  display: none;
}

.lexical-panel>summary::after,
.history-panel>summary::after {
  content: "▾";
  margin-left: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}

.lexical-panel:not([open])>summary::after,
.history-panel:not([open])>summary::after {
  content: "▸";
}

.lexical-body {
  padding-top: 8px;
}

.panel-inline-actions {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  align-items: center;
}

.lexical-panel[open]>.panel-inline-actions,
.history-panel[open]>.panel-inline-actions {
  display: flex;
}

.btn {
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fffaf3;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  box-shadow: 0 10px 20px rgba(203, 85, 40, 0.24);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(203, 85, 40, 0.28);
}

.btn.secondary {
  background: rgba(47, 122, 107, 0.14);
  color: var(--accent-2);
  border: 1px solid rgba(47, 122, 107, 0.35);
  box-shadow: none;
}

.btn.secondary:hover {
  box-shadow: none;
}

.btn.ghost {
  background: rgba(44, 36, 27, 0.08);
  color: var(--ink-soft);
  border: 1px solid rgba(44, 36, 27, 0.18);
  box-shadow: none;
}

.btn.warn {
  background: rgba(120, 40, 32, 0.88);
  box-shadow: 0 10px 20px rgba(120, 40, 32, 0.24);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.settings-panel {
  margin-top: 12px;
  border: 1px dashed rgba(44, 36, 27, 0.22);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.63);
}

.settings-panel summary {
  cursor: pointer;
  user-select: none;
  padding: 10px 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 12px 12px;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting.full {
  grid-column: 1 / -1;
}

.setting label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 700;
}

.setting.check {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(44, 36, 27, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.65);
}

.setting.check label {
  margin: 0;
  letter-spacing: 0.04em;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.phase-card {
  border: 1px solid rgba(44, 36, 27, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.64);
  padding: 14px;
  margin: 10px 0 12px;
}

.progress-track {
  margin-top: 2px;
  height: 11px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(44, 36, 27, 0.14);
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent-3), var(--accent));
  transition: width 0.28s ease;
}

.controls {
  margin-bottom: 8px;
}

.controls .btn:not(:first-child) {
  background: rgba(44, 36, 27, 0.08);
  color: var(--ink-soft);
  border: 1px solid rgba(44, 36, 27, 0.18);
  box-shadow: none;
}

.controls .btn:not(:first-child):hover {
  box-shadow: none;
}

.notice {
  min-height: 22px;
  margin: 8px 0;
  color: var(--ink-soft);
  font-size: 14px;
}

#sessionNotice {
  min-height: 0;
  margin: 0;
}

#sessionNotice:not(:empty) {
  min-height: 22px;
  margin: 8px 0;
}

.timeline {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.timeline-item {
  border: 1px solid rgba(44, 36, 27, 0.13);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  padding: 10px 10px 9px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.timeline-item .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--ink-soft);
  font-size: 11px;
}

.timeline-item .word {
  font-size: 16px;
  font-weight: 700;
}

.timeline-item .order {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.timeline-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(44, 36, 27, 0.2);
  background: rgba(128, 128, 128, 0.38);
  flex: none;
}

.timeline-dot.pending {
  background: rgba(128, 128, 128, 0.35);
}

.timeline-dot.playing {
  background: rgba(203, 85, 40, 0.9);
  border-color: rgba(203, 85, 40, 0.9);
}

.timeline-dot.done {
  background: rgba(47, 122, 107, 0.9);
  border-color: rgba(47, 122, 107, 0.9);
}

.timeline-dot.skipped {
  background: rgba(102, 87, 71, 0.72);
  border-color: rgba(102, 87, 71, 0.72);
}

.timeline-item.playing {
  border-color: rgba(203, 85, 40, 0.55);
  box-shadow: 0 0 0 2px rgba(203, 85, 40, 0.16);
  animation: pulse 1.1s ease-in-out infinite;
}

.timeline-item.done {
  border-color: rgba(47, 122, 107, 0.48);
  background: rgba(228, 248, 241, 0.72);
}

.timeline-item.skipped {
  border-color: rgba(44, 36, 27, 0.22);
  background: rgba(255, 255, 255, 0.66);
}

.word-cards {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.history-block {
  margin-top: 8px;
  padding-top: 0;
}

.history-list {
  display: grid;
  gap: 0;
}

.history-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-top: 1px dashed rgba(44, 36, 27, 0.18);
}

.history-entry:first-child {
  border-top: 0;
}

.history-line {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 2px;
  text-align: left;
  color: var(--ink-soft);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.history-line:hover {
  color: var(--ink);
}

.history-delete {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 12px;
  padding: 4px 2px;
  cursor: pointer;
}

.history-delete:hover {
  color: #7d3028;
}

.history-line:disabled,
.history-delete:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.word-card {
  border: 1px solid rgba(44, 36, 27, 0.14);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.76);
  min-height: 175px;
}

.word-card.valid {
  border-color: rgba(47, 122, 107, 0.45);
}

.word-card.invalid {
  border-color: rgba(120, 40, 32, 0.42);
}

.word-card.loading {
  opacity: 0.65;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.card-head h3 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 26px;
  line-height: 1;
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
  border: 1px solid rgba(44, 36, 27, 0.18);
  background: rgba(160, 160, 160, 0.45);
}

.status-dot.pass {
  background: #2f7a6b;
  border-color: rgba(47, 122, 107, 0.72);
}

.status-dot.review {
  background: rgba(160, 160, 160, 0.45);
  border-color: rgba(120, 120, 120, 0.4);
}

.card-group {
  margin-top: 8px;
}

.card-group p {
  margin: 0 0 5px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  background: rgba(44, 36, 27, 0.08);
  color: var(--ink-soft);
}

.card-def {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.placeholder {
  border: 1px dashed rgba(44, 36, 27, 0.24);
  border-radius: 14px;
  padding: 18px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.46);
  text-align: center;
}

.reveal {
  animation: rise 0.55s ease both;
}

.reveal:nth-child(2) {
  animation-delay: 0.07s;
}

.reveal:nth-child(3) {
  animation-delay: 0.12s;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-1px);
  }

  100% {
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .app {
    width: min(1180px, 100% - 20px);
  }

  .app-header {
    flex-direction: column;
  }

  .stats {
    width: 100%;
  }

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

  .timeline {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .timeline {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .panel {
    padding: 14px;
  }

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

  .timeline {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .word-cards {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
