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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --card-bg: #22223a;
  --card-flipped: #2a2a45;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.3);
  --complete: #3a3a50;
  --complete-text: #555570;
  --danger: #ff4757;
  --success: #2ed573;
  --type-vocab: #ff6b81;
  --type-lingo: #ffa502;
  --type-reading: #70a1ff;
  --type-listening: #7bed9f;
  --type-speaking: #eccc68;
  --type-languish: #a29bfe;
  --type-wild: #ff6348;
  --radius: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  max-width: 430px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

header {
  padding: 16px 20px 8px;
  text-align: center;
  position: relative;
}

#btn-settings {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

#btn-settings:active {
  color: var(--text);
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

#date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
}

#date-display {
  font-size: 13px;
  color: var(--text-dim);
  min-width: 180px;
  text-align: center;
}

#date-display.is-today {
  color: var(--text-dim);
}

#date-display:not(.is-today) {
  color: var(--accent);
}

#btn-prev-day, #btn-next-day {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

#btn-prev-day:active, #btn-next-day:active {
  color: var(--text);
}

#btn-next-day.at-today {
  opacity: 0.2;
  pointer-events: none;
}

/* ─── Card List ─── */
#card-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

#card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 16px;
  transition: opacity 0.2s;
  cursor: default;
}

.list-row.is-vocab {
  cursor: pointer;
}

.list-row.is-vocab:active {
  opacity: 0.8;
}

.list-row.completed {
  opacity: 0.4;
}

.row-type-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 4px 0;
  border-radius: 20px;
  background: rgba(255,255,255,0.06);
  white-space: nowrap;
  flex-shrink: 0;
  width: 72px;
  text-align: center;
}

.row-type-Vocab .row-type-badge { color: var(--type-vocab); }
.row-type-Lingo .row-type-badge { color: var(--type-lingo); }
.row-type-Reading .row-type-badge { color: var(--type-reading); }
.row-type-Listening .row-type-badge { color: var(--type-listening); }
.row-type-Speaking .row-type-badge { color: var(--type-speaking); }
.row-type-Languish .row-type-badge { color: var(--type-languish); }
.row-type-Wild .row-type-badge { color: var(--type-wild); }

.row-content {
  flex: 1;
  min-width: 0;
}

.row-front {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-schedule {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.row-check {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--text-dim);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  color: transparent;
  font-size: 14px;
}

.row-check:active {
  transform: scale(0.9);
}

.list-row.completed .row-check {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

/* ─── Vocab Detail Overlay ─── */
#vocab-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

#vocab-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#vocab-detail {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#vocab-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  z-index: 2;
}

#vocab-close:active {
  color: var(--text);
}

.card {
  width: 100%;
  aspect-ratio: 3/4;
  max-height: 420px;
  cursor: pointer;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.card.flipped {
  transform: rotateY(180deg);
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.card-front, .card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}

.card-front {
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.06);
}

.card-back {
  background: var(--card-flipped);
  border: 1px solid rgba(255,255,255,0.08);
  transform: rotateY(180deg);
}

.card-type-badge {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255,255,255,0.08);
}

.card-content {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-line;
}

.card-front .card-content {
  color: var(--text);
}

.card-back .card-content {
  color: var(--text-dim);
  font-size: 22px;
  font-weight: 400;
}

/* Type colors on card */
.type-Vocab .card-type-badge { color: var(--type-vocab); }

.flip-hint {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-dim);
  opacity: 0.6;
}

/* ─── Manage Screen ─── */
.screen {
  position: absolute;
  inset: 0;
  top: 0;
  background: var(--bg);
  z-index: 10;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  scrollbar-width: none;
}

.screen::-webkit-scrollbar {
  display: none;
}

.btn-row {
  display: flex;
  gap: 10px;
}

.btn-row .btn-secondary {
  flex: 1;
}

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

.manage-header h2 {
  font-size: 22px;
}

#btn-close-manage {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

#btn-close-manage:active {
  color: var(--text);
}

.manage-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.manage-section h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.help-text {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

textarea {
  width: 100%;
  min-height: 100px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 12px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
  resize: vertical;
  margin-bottom: 12px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

select, input[type="text"], input[type="date"] {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  margin-bottom: 8px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn-danger {
  background: rgba(255, 71, 87, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 71, 87, 0.3);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.danger-zone {
  border: 1px solid rgba(255, 71, 87, 0.2);
}

#deck-stats {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-dim);
}

.hidden {
  display: none !important;
}

#empty-state {
  text-align: center;
  color: var(--text-dim);
  padding-top: 40px;
}

#empty-state p {
  margin-bottom: 8px;
}

#empty-state .sub {
  font-size: 13px;
  opacity: 0.6;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2s forwards;
  border: 1px solid rgba(255,255,255,0.1);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
