/* Flash! — kid/tablet-friendly theme */

:root {
  --bg-a: #667eea;
  --bg-b: #764ba2;
  --card: #fffef9;
  --ink: #3b3354;
  --ink-soft: #6b6580;
  --accent: #6c5ce7;
  --accent-ink: #fff;
  --green: #27ae60;
  --yellow: #f39c12;
  --orange: #e67e22;
  --red: #e74c3c;
  --radius: 1rem;
  --shadow: 0 0.5rem 1.5rem rgba(20, 10, 50, 0.25);
}

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

html { font-size: 17px; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-a) 0%, var(--bg-b) 100%) fixed;
  color: var(--ink);
  touch-action: manipulation;
}

#app { max-width: 46rem; margin: 0 auto; padding: 1rem 1rem 4rem; }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; }
a { color: inherit; }

/* ---- header ---- */
.page-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0 1rem; color: #fff;
}
.page-title { font-size: 1.5rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-link {
  font-size: 2rem; line-height: 1; text-decoration: none; padding: 0 0.5rem 0.25rem;
  background: rgba(255,255,255,0.15); border-radius: 0.75rem;
}
.header-actions { display: flex; gap: 0.5rem; }
.header-btn {
  background: rgba(255,255,255,0.15); border-radius: 0.75rem;
  padding: 0.45rem 0.8rem; color: #fff; font-size: 1rem; text-decoration: none;
}
.header-btn:active { background: rgba(255,255,255,0.3); }

/* ---- buttons ---- */
.btn {
  display: inline-block; text-align: center; text-decoration: none;
  padding: 0.7rem 1.3rem; border-radius: 0.9rem; font-weight: 600; font-size: 1rem;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost   { background: rgba(0,0,0,0.07); color: var(--ink); }
.btn-danger  { background: var(--red); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ---- panels ---- */
.panel {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem;
}
.panel h2 { font-size: 1.05rem; color: var(--ink-soft); margin-bottom: 0.75rem; }
.muted { color: var(--ink-soft); }
.error-page { color: #fff; text-align: center; padding: 3rem 0; }

/* ---- profile picker ---- */
.picker { text-align: center; padding-top: 8vh; }
.logo { color: #fff; font-size: 3rem; margin-bottom: 0.25rem; text-shadow: 0 2px 12px rgba(0,0,0,0.25); }
.logo-sub { color: rgba(255,255,255,0.85); margin-bottom: 2.5rem; }
.tiles { display: flex; flex-wrap: wrap; gap: 1.25rem; justify-content: center; }
.profile-tile {
  background: var(--card); border-radius: 1.25rem; box-shadow: var(--shadow);
  width: 9rem; padding: 1.5rem 1rem; display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
}
.profile-tile:active { transform: scale(0.96); }
.profile-avatar { font-size: 3rem; }
.profile-name { font-weight: 700; font-size: 1.15rem; }

/* ---- PIN pad ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(30, 20, 60, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 10;
}
.dialog {
  background: var(--card); border-radius: 1.25rem; box-shadow: var(--shadow);
  padding: 1.5rem; width: 100%; max-width: 22rem; text-align: center;
}
.dialog p { margin-bottom: 1rem; font-weight: 600; }
.dialog-buttons { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1.25rem; }
.dialog-input {
  width: 100%; padding: 0.7rem 0.9rem; border: 2px solid #ddd; border-radius: 0.75rem;
  font-size: 1.05rem;
}
.dialog-input:focus { outline: none; border-color: var(--accent); }

.pin-title { font-size: 1.2rem; margin-bottom: 0.25rem; }
.pin-dots { font-size: 1.6rem; letter-spacing: 0.4rem; min-height: 2.2rem; margin: 0.75rem 0; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.pin-key {
  font-size: 1.5rem; font-weight: 600; padding: 0.8rem 0;
  background: rgba(0,0,0,0.06); border-radius: 0.9rem;
}
.pin-key:active { background: rgba(0,0,0,0.15); }
.pin-key.pin-ok { background: var(--green); color: #fff; }
.pin-error { color: var(--red); min-height: 1.4rem; font-weight: 600; margin-top: 0.75rem; }
.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-5px); }
}

/* ---- deck list ---- */
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 1rem; }
.deck-tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem; text-align: left; display: block; text-decoration: none;
}
.deck-tile:active { transform: scale(0.98); }
.deck-tile h3 { font-size: 1.2rem; margin-bottom: 0.35rem; overflow-wrap: anywhere; }
.deck-tile .muted { font-size: 0.95rem; }
.deck-new { border: 3px dashed rgba(255,255,255,0.6); background: transparent; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; font-weight: 700; min-height: 6rem; }
.result-chip {
  display: inline-block; margin-top: 0.5rem; padding: 0.15rem 0.6rem; border-radius: 1rem;
  background: rgba(108, 92, 231, 0.12); color: var(--accent); font-size: 0.85rem; font-weight: 700;
}

/* ---- deck detail ---- */
.mode-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
.mode-btn {
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 1.1rem 0.5rem; font-size: 1.1rem; font-weight: 700; text-decoration: none; text-align: center;
}
.mode-btn:active { transform: scale(0.97); }
.mode-btn .mode-emoji { display: block; font-size: 1.6rem; margin-bottom: 0.25rem; }
.mode-btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }

.opt-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.9rem; }
.seg { display: flex; background: rgba(0,0,0,0.07); border-radius: 0.8rem; padding: 0.2rem; flex: 1; }
.seg button { flex: 1; padding: 0.45rem 0.6rem; border-radius: 0.65rem; font-weight: 600; font-size: 0.92rem; color: var(--ink-soft); white-space: nowrap; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,0.15); }

.card-row {
  display: flex; gap: 0.75rem; padding: 0.55rem 0; border-bottom: 1px solid rgba(0,0,0,0.07);
  align-items: baseline;
}
.card-row:last-child { border-bottom: none; }
.card-term { font-weight: 700; flex: 1; overflow-wrap: anywhere; }
.card-def { flex: 1.4; color: var(--ink-soft); overflow-wrap: anywhere; }

.result-row { display: flex; gap: 0.75rem; padding: 0.4rem 0; align-items: baseline; }
.result-mode { font-weight: 700; text-transform: capitalize; width: 4.5rem; }
.result-score { font-weight: 600; }
.result-when { margin-left: auto; color: var(--ink-soft); font-size: 0.9rem; }

.deck-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

/* ---- editor ---- */
.edit-row { display: flex; gap: 0.5rem; align-items: center; padding: 0.35rem 0; }
.edit-row input {
  flex: 1; min-width: 0; padding: 0.55rem 0.7rem; border: 2px solid transparent;
  background: rgba(0,0,0,0.05); border-radius: 0.6rem;
}
.edit-row input:focus { outline: none; border-color: var(--accent); background: #fff; }
.icon-btn { font-size: 1.1rem; padding: 0.4rem 0.55rem; border-radius: 0.6rem; background: rgba(0,0,0,0.05); }
.icon-btn:active { background: rgba(0,0,0,0.15); }

/* ---- importer ---- */
.import-controls { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.import-controls label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--ink-soft); font-weight: 600; }
.import-controls select, .import-controls input {
  padding: 0.45rem 0.6rem; border: 2px solid #ddd; border-radius: 0.6rem; background: #fff;
}
.import-textarea {
  width: 100%; min-height: 11rem; padding: 0.8rem; border: 2px solid #ddd; border-radius: 0.75rem;
  resize: vertical; font-family: ui-monospace, monospace; font-size: 0.9rem;
}
.import-textarea:focus { outline: none; border-color: var(--accent); }
.preview-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.preview-table td { padding: 0.35rem 0.5rem; border-bottom: 1px solid rgba(0,0,0,0.07); overflow-wrap: anywhere; }

/* ---- study screens ---- */
.study-top { display: flex; align-items: center; gap: 0.75rem; color: #fff; padding: 0.5rem 0 1rem; }
.study-count { font-weight: 700; white-space: nowrap; }
.progress-track { flex: 1; height: 0.7rem; background: rgba(255,255,255,0.25); border-radius: 1rem; overflow: hidden; }
.progress-fill { height: 100%; background: #fff; border-radius: 1rem; width: 0; transition: width 0.25s; }

.study-card {
  background: var(--card); border-radius: 1.25rem; box-shadow: var(--shadow);
  min-height: 15rem; display: flex; align-items: center; justify-content: center;
  padding: 2rem 1.5rem; text-align: center; font-size: 1.7rem; font-weight: 700;
  overflow-wrap: anywhere; cursor: pointer; user-select: none;
}
.study-card-wrap .flip-hint {
  position: absolute; bottom: 0.8rem; left: 0; right: 0; text-align: center;
  font-size: 0.85rem; font-weight: 500; color: var(--ink-soft); pointer-events: none;
}
.study-card-wrap { position: relative; display: flex; margin-bottom: 1rem; }
.study-card-wrap .study-card { flex: 1; }
.study-side-label {
  position: absolute; top: 0.8rem; left: 1.2rem; font-size: 0.8rem; font-weight: 700;
  color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em;
}

.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.grade-btn { color: #fff; border-radius: 0.9rem; padding: 0.9rem 0.3rem; font-weight: 700; font-size: 1rem; }
.grade-btn:active { transform: scale(0.96); }
.grade-0 { background: var(--red); } .grade-1 { background: var(--orange); }
.grade-2 { background: var(--yellow); } .grade-3 { background: var(--green); }
.test-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

/* ---- typing ---- */
.type-input {
  width: 100%; padding: 0.85rem 1rem; font-size: 1.25rem; border: 3px solid #ddd;
  border-radius: 0.9rem; margin-bottom: 0.6rem; background: #fff;
}
.type-input:focus { outline: none; border-color: var(--accent); }
.type-input.flash-good { border-color: var(--green); background: #eafaf1; }
.type-input.flash-bad { border-color: var(--red); }
.accent-bar { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.75rem; }
.accent-key {
  font-size: 1.15rem; padding: 0.45rem 0.7rem; background: var(--card);
  border-radius: 0.6rem; box-shadow: 0 2px 6px rgba(0,0,0,0.18); font-weight: 600;
}
.accent-key:active { transform: scale(0.94); }
.judge-banner { border-radius: 0.9rem; padding: 0.9rem 1rem; margin-bottom: 0.75rem; font-weight: 600; }
.judge-almost { background: #fdf3d7; color: #8a6d00; }
.judge-wrong { background: #fde3e0; color: #a72313; }
.judge-banner .expected { display: block; font-size: 1.35rem; margin-top: 0.3rem; color: var(--ink); }
.judge-links { margin-top: 0.5rem; font-size: 0.9rem; font-weight: 500; }
.judge-links a { cursor: pointer; text-decoration: underline; }

/* ---- end screen ---- */
.end-screen { text-align: center; }
.end-big { font-size: 3rem; margin: 0.5rem 0; }
.end-title { font-size: 1.5rem; margin-bottom: 0.25rem; }
.end-buttons { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1.25rem; flex-wrap: wrap; }
.missed-list { text-align: left; margin-top: 1rem; }

/* ---- admin/trash ---- */
.admin-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0; border-bottom: 1px solid rgba(0,0,0,0.07); flex-wrap: wrap; }
.admin-row:last-child { border-bottom: none; }
.admin-name { font-weight: 700; flex: 1; min-width: 8rem; }
.admin-row .btn { padding: 0.4rem 0.8rem; font-size: 0.88rem; }
.trash-row { display: flex; align-items: baseline; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid rgba(0,0,0,0.07); flex-wrap: wrap; }
.trash-row:last-child { border-bottom: none; }
.trash-what { flex: 1; min-width: 10rem; overflow-wrap: anywhere; }

/* ---- toast ---- */
#toast { position: fixed; bottom: 1.25rem; left: 0; right: 0; display: flex; justify-content: center; z-index: 20; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; border-radius: 0.9rem; padding: 0.8rem 1.2rem;
  box-shadow: var(--shadow); display: flex; gap: 1rem; align-items: center; pointer-events: auto;
  max-width: 90vw;
}
.toast-action { color: #ffd166; font-weight: 700; }

@media (max-width: 480px) {
  html { font-size: 16px; }
  .mode-buttons { grid-template-columns: 1fr; }
  .grade-row { grid-template-columns: repeat(2, 1fr); }
}
