:root {
  --bg: #0f0e0b;
  --surface: #1a1914;
  --card: #211f18;
  --border: #2e2c22;
  --accent: #e8c84a;
  --accent-hover: #f0d55a;
  --accent2: #c4523a;
  --text: #f0ead6;
  --muted: #7a7460;
  --correct: #5a9e6f;
  --wrong: #c4523a;
  --hover-bg: #1e1c14;
  --selected-bg: #221f10;
}

[data-theme="light"] {
  --bg: #f9f8f6;
  --surface: #f0eee5;
  --card: #ffffff;
  --border: #e0dccc;
  --accent: #d4a017;
  --accent-hover: #b88a10;
  --accent2: #c4523a;
  --text: #2c2a25;
  --muted: #857e67;
  --correct: #3b8253;
  --wrong: #c4523a;
  --hover-bg: #ffffff;
  --selected-bg: #fcf4db;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px 80px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 999;
  opacity: 0.4;
}

header {
  text-align: center;
  margin-bottom: 48px;
  animation: fadeDown 0.7s ease both;
}

.eyebrow {
  font-family: "DM Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

h1 {
  font-family: "Playfair Display", serif;
  font-size: clamp(2.4rem, 5vw, 3.8rem);
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
h1 em {
  color: var(--accent);
  font-style: italic;
}

.subtitle {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 300;
}

/* ── Import Layout ── */
.import-split {
  width: 100%;
  max-width: 960px;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 32px;
  animation: fadeDown 0.7s 0.1s ease both;
}

/* ── Left Panel (Local) ── */
.panel-local {
  display: flex;
  flex-direction: column;
}
.panel-local .drop-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 2px dashed var(--border);
  background: transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 300px;
  position: relative;
}
.panel-local .drop-area:hover,
.panel-local .drop-area.dragover {
  border-color: var(--accent);
  background: var(--hover-bg);
}
.drop-icon {
  font-size: 2.2rem;
  margin-bottom: 12px;
  display: block;
}
.drop-label {
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
  padding: 0 20px;
}
.drop-label strong {
  color: var(--accent);
  font-weight: 500;
}
.file-name {
  margin-top: 12px;
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  color: var(--accent2);
  display: none;
}
#fileInput {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* ── Right Panel (Server) ── */
.panel-server {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-server h3 {
  font-family: "DM Sans", sans-serif;
  font-weight: 500;
  font-size: 1.1rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
}
.panel-server .sets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding-right: 6px;
  flex: 1;
  align-content: start;
}

.live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--correct);
  margin-left: 8px;
  opacity: 0;
  transition: opacity 0.3s;
}
.live-dot.server-ok {
  opacity: 1;
}

/* ── Sets Grid Items ── */
.set-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition:
    border-color 0.2s,
    background 0.2s,
    transform 0.15s;
}
.set-card:hover {
  border-color: var(--accent);
  background: var(--hover-bg);
  transform: translateY(-1px);
}
.set-card.selected {
  border-color: var(--accent);
  background: var(--selected-bg);
}
.set-card-name {
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  color: var(--text);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.set-card-meta {
  font-size: 0.72rem;
  color: var(--muted);
}

.sets-msg {
  text-align: center;
  color: var(--muted);
  font-size: 0.83rem;
  padding: 22px 0;
  line-height: 1.7;
}
.sets-msg code {
  font-family: "DM Mono", monospace;
  color: var(--accent2);
  font-size: 0.78rem;
}
.sets-msg.loading {
  font-family: "DM Mono", monospace;
  letter-spacing: 0.05em;
  animation: pulse 1.2s ease infinite;
}

/* ── Start button ── */
.btn-load {
  display: none;
  margin: 18px auto 0;
  padding: 12px 32px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-family: "DM Mono", monospace;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  font-weight: 500;
  transition:
    background 0.2s,
    transform 0.1s;
  /* flex width handling */
  width: 100%;
}
.btn-load.visible {
  display: block;
}
.btn-load:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}
.btn-load:active {
  transform: translateY(0);
}

/* ── Exercise zone ── */
#exercise-zone {
  width: 100%;
  max-width: 680px;
  display: none;
}

.progress-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 4px;
  margin-bottom: 36px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 40px;
  animation: slideUp 0.4s ease both;
}
.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.tense-tag {
  font-family: "DM Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: var(--border);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 4px;
}
.counter {
  font-family: "DM Mono", monospace;
  font-size: 11px;
  color: var(--muted);
}

.hint-block {
  margin-bottom: 20px;
  padding: 14px 18px;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.hint-block strong {
  color: var(--text);
  font-family: "Playfair Display", serif;
  font-style: italic;
  font-size: 1rem;
}

.sentence {
  font-size: 1.25rem;
  line-height: 1.9;
  margin-bottom: 28px;
  font-weight: 300;
}

.blank-input {
  display: inline-block;
  border: none;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  font-size: 1.15rem;
  width: 140px;
  padding: 2px 6px;
  outline: none;
  text-align: center;
  transition:
    border-color 0.2s,
    background 0.3s;
  border-radius: 4px 4px 0 0;
}
.blank-input::placeholder {
  color: var(--muted);
  opacity: 0.5;
}
.blank-input:focus {
  border-bottom-color: var(--accent-hover);
}
.blank-input.correct {
  border-bottom-color: var(--correct);
  color: var(--correct);
  background: rgba(90, 158, 111, 0.07);
}
.blank-input.wrong {
  border-bottom-color: var(--wrong);
  color: var(--wrong);
  background: rgba(196, 82, 58, 0.07);
  animation: shake 0.4s ease;
}

.feedback {
  min-height: 22px;
  margin-bottom: 20px;
  font-size: 0.85rem;
}
.feedback.correct {
  color: var(--correct);
}
.feedback.wrong {
  color: var(--wrong);
}

.card-actions {
  display: flex;
  gap: 12px;
}

.btn {
  padding: 11px 24px;
  border-radius: 6px;
  border: none;
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}
.btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}
.btn-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--muted);
  color: var(--text);
}

/* ── Results ── */
.results-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  text-align: center;
}
.results-title {
  font-family: "Playfair Display", serif;
  font-size: 2rem;
  margin-bottom: 8px;
}
.score-display {
  font-size: 4rem;
  font-weight: 700;
  font-family: "DM Mono", monospace;
  color: var(--accent);
  margin: 20px 0;
}
.score-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 32px;
}

.review-list {
  text-align: left;
  margin: 24px 0 32px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.review-item {
  background: var(--surface);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.review-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.review-item.ok .dot {
  background: var(--correct);
}
.review-item.ko .dot {
  background: var(--wrong);
}
.review-item .answer {
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 3px;
}
.review-item .answer span {
  color: var(--accent2);
}

/* ── CSV info ── */
.csv-info {
  width: 100%;
  max-width: 680px;
  margin-top: 48px;
  padding: 28px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  animation: fadeDown 0.7s 0.2s ease both;
}
.csv-info h3 {
  font-family: "Playfair Display", serif;
  font-size: 1.1rem;
  margin-bottom: 14px;
}
.csv-info p {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.6;
}

pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: "DM Mono", monospace;
  font-size: 0.72rem;
  color: var(--accent);
  overflow-x: auto;
  line-height: 1.7;
}

.btn-download-csv {
  margin-top: 16px;
  display: inline-block;
  padding: 9px 20px;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  font-family: "DM Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}
.btn-download-csv:hover {
  background: var(--accent);
  color: var(--bg);
}

/* ── Modal CSV Info ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.25s ease;
}
.modal-content.csv-info {
  margin-top: 0;
  position: relative;
  max-width: 90vw;
  width: 680px;
  animation: scaleIn 0.2s ease;
}
.close-modal {
  position: absolute;
  top: 16px;
  right: 18px;
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s;
  line-height: 1;
}
.close-modal:hover {
  color: var(--accent);
}

/* ── Animations ── */
@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}
@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

/* ── Top Controls ── */
.top-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 12px;
  z-index: 1000;
}

.icon-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text);
  transition: all 0.2s;
}
.icon-toggle:hover {
  background: var(--hover-bg);
  border-color: var(--accent);
  transform: scale(1.05);
}
#infoToggle {
  font-family: "DM Mono", monospace;
  font-weight: 500;
  font-size: 1.4rem;
}
.theme-toggle .icon-moon {
  display: none;
}
[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}
[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}
