:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --success: #059669;
  --finish: #7c3aed;
  --finish-dark: #6d28d9;
  --bg: #f1f5f9;
  --card-bg: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --radius: 18px;
}

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

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text);
  background: radial-gradient(circle at top left, #e0f2fe 0, transparent 32rem), var(--bg);
  font-family: ui-sans-serif, "Segoe UI", system-ui, sans-serif;
}

.container {
  width: 100%;
  max-width: 560px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: 0 4px 28px rgba(0, 0, 0, .09);
}

.panel-center {
  text-align: center;
}

.brand {
  color: var(--primary);
  font-size: 1.9rem;
  font-weight: 800;
}

.subtitle {
  margin-top: 4px;
  margin-bottom: 24px;
  color: var(--muted);
  font-size: .92rem;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.1rem;
  font-weight: 700;
}

a.btn {
  text-decoration: none;
}

.btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 22px;
  border: 0;
  border-radius: 11px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: transform .12s, background .12s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-success {
  color: #fff;
  background: var(--success);
}

.btn-success:hover {
  background: #047857;
}

.btn-ghost {
  color: var(--text);
  background: var(--border);
}

.btn-ghost:hover {
  background: #cbd5e1;
}

.btn-finish {
  color: #fff;
  background: var(--finish);
}

.btn-finish:hover {
  background: var(--finish-dark);
}

.btn-small {
  padding: 10px;
  font-size: .9rem;
}

.btn-col,
.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.stack-sm {
  margin-top: 14px;
}

.goal-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border-radius: 11px;
  background: var(--bg);
}

.goal-opt {
  flex: 1;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  text-align: center;
  transition: all .15s;
}

.goal-opt.active {
  color: var(--primary);
  background: var(--card-bg);
  font-weight: 700;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .1);
}

.input-wrap {
  margin-bottom: 18px;
}

.input-wrap label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 500;
}

.input-wrap input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 11px;
  outline: none;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  transition: border-color .15s;
}

.input-wrap input:focus {
  border-color: var(--primary);
}

.info-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 20px;
  padding: 10px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  color: #1d4ed8;
  background: #eff6ff;
  font-size: .83rem;
}

.link-btn {
  border: 0;
  color: #6366f1;
  background: none;
  cursor: pointer;
  font-size: .8rem;
  text-decoration: underline;
  white-space: nowrap;
}

.stats-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  flex: 1;
  padding: 10px 8px;
  border-radius: 12px;
  background: var(--card-bg);
  text-align: center;
}

.stat-val {
  color: var(--primary);
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
}

.stat-label {
  margin-top: 3px;
  color: var(--muted);
  font-size: .68rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.prog-wrap {
  margin-bottom: 16px;
}

.prog-bar {
  height: 7px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--border);
}

.prog-fill {
  width: 0%;
  height: 100%;
  border-radius: 4px;
  background: var(--primary);
  transition: width .35s ease;
}

.prog-text {
  margin-top: 4px;
  color: var(--muted);
  font-size: .78rem;
  text-align: right;
}

.flashcard {
  position: relative;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  padding: 36px 28px;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: #fff;
  text-align: center;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .05);
  transition: border-color .3s, box-shadow .3s;
}

.flashcard.revealed {
  border-color: var(--success);
  box-shadow: 0 2px 20px rgba(5, 150, 105, .15);
}

.card-badge {
  position: absolute;
  top: 11px;
  right: 13px;
  padding: 2px 8px;
  border-radius: 20px;
  color: var(--muted);
  background: var(--bg);
  font-size: .7rem;
}

.card-type {
  position: absolute;
  top: 10px;
  left: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.card-type.type-s {
  border: 1px solid #c7d2fe;
  color: #4338ca;
  background: #eef2ff;
}

.card-type.type-p {
  border: 1px solid #fde68a;
  color: #b45309;
  background: #fffbeb;
}

.card-type:empty {
  display: none;
}

.card-front {
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.55;
}

.word-lnk {
  display: inline-block;
  border-bottom: 1px dashed transparent;
  cursor: pointer;
  transition: all .2s;
}

.word-lnk:active {
  background: #e0e7ff;
  transform: scale(1.1);
}

@media (hover: hover) {
  .word-lnk:hover {
    border-bottom-color: var(--primary);
    color: var(--primary);
  }
}

.speaker-btn {
  display: inline-block;
  margin-right: 8px;
  cursor: pointer;
  font-size: 1.4rem;
  user-select: none;
  vertical-align: middle;
  transition: transform .1s;
}

.speaker-btn:active {
  transform: scale(1.2);
}

.card-back {
  width: 100%;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px dashed #d1fae5;
  color: var(--success);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.45;
  animation: fadeIn .25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hidden {
  display: none !important;
}

.key-hint {
  margin-top: 10px;
  color: #94a3b8;
  font-size: .77rem;
  text-align: center;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #f8fafc;
  font-family: inherit;
  font-size: .73rem;
}

.big-emoji {
  display: block;
  margin-bottom: 12px;
  font-size: 3.5rem;
  text-align: center;
}

.cg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 20px 0;
}

.cs {
  padding: 18px;
  border-radius: 12px;
  background: var(--bg);
  text-align: center;
}

.cs-val {
  color: var(--primary);
  font-size: 2.1rem;
  font-weight: 800;
}

.cs-lbl {
  margin-top: 3px;
  color: var(--muted);
  font-size: .8rem;
}

.summary-stats {
  margin: 20px 0;
  padding: 16px;
  background: var(--bg);
  border-radius: 12px;
}

.summary-stats h3 {
  margin-bottom: 14px;
  font-size: 1rem;
  color: var(--text);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--card-bg);
  border-radius: 8px;
}

.stat-icon {
  font-size: 1.5rem;
  min-width: 32px;
  text-align: center;
}

.stat-text {
  flex: 1;
}

.stat-num {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  font-size: .75rem;
  color: var(--muted);
  margin-top: 2px;
}

.divider {
  margin: 20px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.update-section {
  margin-top: 16px;
}

.update-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border: 0;
  color: var(--muted);
  background: none;
  cursor: pointer;
  font-size: .83rem;
  text-align: left;
}

.update-toggle:hover {
  color: var(--primary);
}

.update-body {
  display: none;
  margin-top: 10px;
}

.update-body.open {
  display: block;
}

.update-body p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.5;
}

.update-body textarea {
  width: 100%;
  min-height: 100px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  outline: none;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: .82rem;
  resize: vertical;
  transition: border-color .15s;
}

.update-body textarea:focus {
  border-color: var(--primary);
}

.update-err,
.update-ok {
  display: none;
  margin-bottom: 8px;
  font-size: .8rem;
}

.update-err {
  color: var(--danger);
}

.update-ok {
  color: var(--success);
}

.last-session {
  margin-top: -18px;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: .75rem;
  text-align: center;
}

.status {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: .8rem;
}

.status.ok {
  color: #065f46;
  background: #d1fae5;
}

.status.err {
  color: var(--danger);
  background: #fee2e2;
}

.status.loading {
  color: #1d4ed8;
  background: #eff6ff;
}

.revealed-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.action-row .btn {
  font-size: 0.8rem;
  padding: 7px 4px !important;
  white-space: nowrap;
}

.delay-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--border);
}

.delay-wrap span {
  margin-left: 4px;
  color: var(--muted);
  font-size: .7rem;
}

.delay-input {
  width: 45px;
  padding: 6px;
  border: 0;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 700;
  text-align: center;
}

.delay-button {
  width: auto;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: .8rem;
}

@media (max-width: 520px) {
  body {
    align-items: flex-start;
    padding: 12px;
  }

  .panel {
    padding: 28px 22px;
  }

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