@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;500;700;800&display=swap');

:root {
  --bg: #fff6fa;
  --panel: #ffffff;
  --primary: #ff8fb5;
  --primary-dark: #f2568f;
  --primary-tint: #ffe1ec;
  --purple: #c7aeff;
  --purple-tint: #eee5ff;
  --mint: #6fe0d1;
  --mint-tint: #dcfbf6;
  --yellow: #ffd873;
  --yellow-tint: #fff3d6;
  --danger: #ff7a8a;
  --danger-tint: #ffe3e6;
  --text: #4a2e3d;
  --text-soft: #9a7c89;
  --shadow-pink: 0 10px 24px -8px rgba(242, 86, 143, 0.35);
  --shadow-pink-sm: 0 6px 14px -6px rgba(242, 86, 143, 0.3);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 12%, var(--purple-tint) 0%, transparent 42%),
    radial-gradient(circle at 92% 8%, var(--yellow-tint) 0%, transparent 38%),
    radial-gradient(circle at 85% 92%, var(--mint-tint) 0%, transparent 40%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

button { font-family: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 2px;
}

/* ---------- Login ---------- */
.login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 48px 36px;
  text-align: center;
  box-shadow: var(--shadow-pink);
  max-width: 380px;
  width: 100%;
}
.login-emoji { font-size: 40px; margin-bottom: 8px; letter-spacing: 4px; }
.login-title {
  font-weight: 800;
  font-size: 34px;
  margin: 0 0 8px;
  color: var(--primary-dark);
}
.login-tagline {
  color: var(--text-soft);
  margin: 0 0 28px;
  font-size: 15px;
}
.error-title { font-weight: 800; font-size: 20px; margin: 0 0 10px; color: var(--danger); }
.error-message { color: var(--text-soft); margin: 0 0 24px; font-size: 14px; line-height: 1.7; white-space: pre-line; text-align: left; }

/* ---------- Shell / header ---------- */
.shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  width: 100%;
  flex: 1;
}
.shell__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.shell__title {
  font-size: 26px;
  font-weight: 800;
  margin: 0;
  color: var(--primary-dark);
}
.shell__subtitle {
  margin: 4px 0 0;
  color: var(--text-soft);
  font-size: 15px;
}
.shell__footer { margin-top: 32px; display: flex; justify-content: center; }

/* ---------- Buttons ---------- */
.candy-btn {
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  background: var(--primary-tint);
  color: var(--primary-dark);
}
.candy-btn:hover { transform: translateY(-2px); }
.candy-btn:active { transform: translateY(0); }
.candy-btn--primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow-pink-sm);
}
.candy-btn--secondary {
  background: linear-gradient(135deg, var(--purple), #a98cf0);
  color: #fff;
  box-shadow: 0 6px 14px -6px rgba(147, 108, 230, 0.45);
}
.candy-btn--ghost {
  background: transparent;
  color: var(--text-soft);
  border: 2px solid #f1d9e2;
}
.candy-btn.is-disabled, .candy-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ---------- Book grid (mypage1) ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}
.book-card {
  background: var(--panel);
  border: none;
  border-radius: var(--radius-md);
  padding: 24px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-pink-sm);
  transition: transform 0.15s ease;
}
.book-card:hover { transform: translateY(-3px) scale(1.02); }
.book-card__emoji { font-size: 34px; }
.book-card__label { font-weight: 700; color: var(--text); }
.admin-entry { margin-top: 28px; display: flex; justify-content: center; }

/* ---------- Unit grid (mypage2) ---------- */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.unit-card {
  background: var(--panel);
  border: none;
  border-radius: var(--radius-md);
  padding: 20px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-pink-sm);
}
.unit-card:not(.is-disabled):hover { transform: translateY(-2px); }
.unit-card.is-disabled { opacity: 0.45; cursor: not-allowed; }
.unit-card__label { font-weight: 700; }

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
}
.badge-notstarted { background: #f1eef1; color: #9d8f96; }
.badge-inprogress { background: var(--yellow-tint); color: #a5780a; }
.badge-complete { background: var(--mint-tint); color: #1f9686; }
.badge-perfect { background: var(--purple-tint); color: #6b46c9; }
.badge-mastered { background: linear-gradient(135deg, var(--primary), var(--purple)); color: #fff; }
.badge-nodata { background: #f2f2f2; color: #b3b3b3; }

/* ---------- Mode tabs / sub-grid (mypage3) ---------- */
.mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.mode-tab {
  border: none;
  background: var(--panel);
  color: var(--text-soft);
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-pink-sm);
}
.mode-tab.is-active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}
.mode-tabs--fixed .mode-tab { cursor: default; }

.sub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.sub-card {
  background: var(--panel);
  border: none;
  border-radius: var(--radius-md);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-pink-sm);
}
.sub-card:hover { transform: translateY(-2px); }
.sub-card__label { font-weight: 700; }
.sub-card__best { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.sub-card__score { font-size: 12px; color: var(--text-soft); }
.sub-card__best--empty { font-size: 12px; color: #c9b8c0; }

.stars { color: var(--yellow); font-size: 18px; letter-spacing: 2px; }

/* ---------- Quiz screen ---------- */
.quiz-shell { max-width: 620px; }
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.quiz-progress { font-weight: 700; color: var(--text-soft); }
.quiz-timer {
  background: var(--yellow-tint);
  color: #9a6d10;
  font-weight: 800;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 15px;
}
.question-card {
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  box-shadow: var(--shadow-pink);
  text-align: center;
}
.question-ja { font-size: 20px; margin: 0 0 14px; line-height: 1.6; }
.question-ja--big { font-size: 26px; font-weight: 700; }
.question-en {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 24px;
  color: var(--primary-dark);
  line-height: 1.7;
}
.question-en--big { font-size: 30px; }
.answer-input {
  width: 100%;
  max-width: 320px;
  padding: 14px 18px;
  border-radius: 999px;
  border: 3px solid var(--primary-tint);
  font-size: 18px;
  text-align: center;
  font-family: inherit;
  color: var(--text);
}
.answer-input--wide { max-width: 100%; }
.answer-input:disabled { background: #faf3f6; }

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 8px;
}
.choice-card {
  border: 3px solid var(--primary-tint);
  background: #fff;
  border-radius: var(--radius-md);
  padding: 20px 12px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.choice-card:not(:disabled):hover { border-color: var(--primary); }
.choice-card--correct { border-color: var(--mint); background: var(--mint-tint); }
.choice-card--wrong { border-color: var(--danger); background: var(--danger-tint); }
.choice-card--disabled { opacity: 0.5; }

.feedback { margin-top: 22px; }
.feedback__msg { font-size: 22px; font-weight: 800; margin: 0; }
.feedback--correct .feedback__msg { color: #1f9686; }
.feedback--wrong .feedback__msg { color: #e0596b; }
.feedback__answer { color: var(--text-soft); margin: 6px 0 0; }

.quiz-actions { display: flex; justify-content: center; margin-top: 24px; }

/* ---------- Result ---------- */
.result-shell { max-width: 520px; text-align: center; }
.result-title { font-size: 24px; font-weight: 800; color: var(--primary-dark); }
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 24px 0;
}
.stat-box {
  background: var(--panel);
  border-radius: var(--radius-md);
  padding: 18px 8px;
  box-shadow: var(--shadow-pink-sm);
}
.stat-box__label { font-size: 12px; color: var(--text-soft); margin-bottom: 6px; }
.stat-box__value { font-size: 20px; font-weight: 800; color: var(--primary-dark); }
.new-record {
  font-weight: 800;
  color: #e0a300;
  margin-bottom: 12px;
  font-size: 17px;
}
.result-stars { font-size: 40px; margin: 12px 0 28px; }
.result-actions { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }

/* ---------- Admin ---------- */
.admin-shell { max-width: 960px; }
.admin-title { color: var(--primary-dark); font-weight: 800; }
.admin-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.admin-tab {
  border: none;
  background: var(--panel);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--text-soft);
  box-shadow: var(--shadow-pink-sm);
}
.admin-tab.is-active { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.admin-tab--small { padding: 7px 14px; font-size: 13px; }
.admin-term-editor {
  background: var(--panel);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-pink-sm);
}
.admin-term-editor__label { font-weight: 700; margin: 0 0 10px; font-size: 14px; }
.admin-term-editor__row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.admin-term-editor__input {
  padding: 10px 14px;
  border-radius: 999px;
  border: 2px solid var(--primary-tint);
  font-family: inherit;
  font-size: 14px;
  min-width: 160px;
}
.admin-term-editor__hint { color: var(--text-soft); font-size: 12px; margin: 10px 0 0; }
.admin-table-wrap { overflow-x: auto; background: var(--panel); border-radius: var(--radius-md); box-shadow: var(--shadow-pink-sm); }
.admin-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.admin-table th, .admin-table td {
  padding: 10px 14px;
  text-align: center;
  border-bottom: 1px solid #f6e6ee;
  white-space: nowrap;
}
.admin-table th { color: var(--text-soft); font-weight: 700; }
.admin-table__user { text-align: left; font-weight: 700; }
.admin-table__score { font-size: 11px; color: var(--text-soft); }
.admin-table__empty { color: #d9c6d0; }

/* ---------- Misc ---------- */
.spinner-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; gap: 14px; color: var(--text-soft); }
.spinner {
  width: 42px; height: 42px;
  border: 5px solid var(--primary-tint);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
  .shell { padding: 20px 14px 48px; }
  .choice-grid { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: 1fr; }
}
