/* ---------- Reset & base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, -apple-system, sans-serif;
  color: #1e293b;
  background: #f1f5f9;
  line-height: 1.5;
}
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

/* ---------- App layout ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: #1e293b;
  color: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-title {
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  color: inherit;
}
.user-summary { font-size: 0.85rem; opacity: 0.9; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

/* ---------- Home ---------- */
.home h1 {
  font-size: 1.1rem;
  margin: 0.5rem 0 1rem;
}
.card-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
}
.big-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 1.25rem 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #ffffff;
  font-size: 1rem;
  text-align: left;
  transition: background 0.1s, transform 0.05s;
}
.big-card:hover { background: #f8fafc; }
.big-card:active { transform: scale(0.99); }
.big-card-title { font-size: 1.25rem; font-weight: 700; }
.big-card-sub { font-size: 0.88rem; color: #475569; }

.settings-bar {
  margin-top: 1.5rem;
  padding: 0.75rem;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
}

/* ---------- Test screen ---------- */
.test-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.link-button {
  background: none;
  border: 0;
  color: #2563eb;
  font-size: 0.95rem;
  padding: 0.25rem;
}
.test-info { font-size: 0.9rem; color: #475569; }

.questions {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.question {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: #475569;
}
.q-num { font-weight: 600; }
.q-consec { font-variant-numeric: tabular-nums; }
.q-consec.mastered { color: #16a34a; font-weight: 700; }

.q-jp { font-size: 1rem; }
.q-jp .hint { color: #0284c7; font-weight: 700; }
.q-jp .hidden-hint {
  /* Render the hint as plain text — drops bold/color emphasis but stays readable. */
}

.q-en {
  font-size: 1.05rem;
  line-height: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
}
.q-en input.blank-input {
  font-size: 1rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  width: auto;
  min-width: 4em;
  font-family: inherit;
}
.q-en input.blank-input:focus { outline: 2px solid #2563eb; outline-offset: -1px; }

.q-en .blank-group { display: inline-flex; gap: 0.25rem; }
.q-en .blank-group input + input { margin-left: 0.1rem; }

.q-foot {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
}
.reveal-button {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  font-size: 0.85rem;
}
.reveal-button.revealed {
  background: #fef3c7;
  border-color: #f59e0b;
}
.q-answer {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f766e;
}
.q-feedback { font-weight: 600; }
.q-feedback.ok  { color: #16a34a; }
.q-feedback.ng  { color: #dc2626; }
.q-feedback.recovered { color: #0d9488; }

.question.revealed { background: #fffbeb; }
.question.correct  { background: #ecfdf5; border-color: #34d399; }
.question.wrong    { background: #fef2f2; border-color: #fca5a5; }

/* ---------- Submit bar ---------- */
.submit-bar {
  position: sticky;
  bottom: 0;
  margin-top: 1rem;
  padding: 0.75rem 0;
  background: linear-gradient(to top, #f1f5f9 70%, rgba(241,245,249,0));
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}
.primary-button {
  background: #2563eb;
  color: #ffffff;
  border: 0;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
}
.primary-button:hover { background: #1d4ed8; }
.secondary-button {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.95rem;
}

/* ---------- Results ---------- */
.results h1 { margin: 0.25rem 0; }
.result-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.result-row {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  background: #ffffff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}
.result-row.correct { background: #ecfdf5; border-color: #34d399; }
.result-row.wrong   { background: #fef2f2; border-color: #fca5a5; }
.result-row .badge {
  font-size: 0.8rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: #f1f5f9;
}

/* ---------- Practice mode ---------- */
.practice-type, .practice-range-set {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  margin: 0 0 0.6rem 0;
  padding: 0.5rem 0.75rem;
}
.practice-type legend, .practice-range-set legend {
  font-size: 0.82rem;
  color: #475569;
  padding: 0 0.25rem;
}
.practice-type label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-right: 0.75rem;
  font-size: 0.95rem;
}
.practice-range-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
#practice-range {
  flex: 1;
  min-width: 10em;
  padding: 0.4rem;
  font-size: 0.95rem;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  background: #ffffff;
}

.practice-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.practice-item {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.q-pstats {
  font-size: 0.82rem;
  color: #475569;
}
.q-pstats .score-pos { color: #16a34a; font-weight: 700; }
.q-pstats .score-neg { color: #dc2626; font-weight: 700; }

/* Highlight the to-be-quizzed bold spans in the practice preview. */
.practice-item .q-en .bold {
  font-weight: 700;
  color: #b91c1c;
  text-decoration: underline;
  text-decoration-color: #fca5a5;
  text-underline-offset: 0.18em;
}
.practice-item .q-jp .bold {
  font-weight: 700;
  color: #0284c7;
}

/* ---------- History ---------- */
.extra-actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.history-filters fieldset {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  background: #ffffff;
  margin: 0;
}
.history-filters legend {
  font-size: 0.78rem;
  color: #475569;
  padding: 0 0.25rem;
}
.history-filters label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-right: 0.5rem;
  font-size: 0.9rem;
}

.history-table-wrap {
  overflow-x: auto;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  table-layout: auto;
}
.history-table thead th {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  color: #334155;
  font-weight: 600;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid #cbd5e1;
  white-space: nowrap;
  font-size: 0.82rem;
}
.history-table tbody td {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}
.history-table tbody tr:nth-child(even) td {
  background: #f8fafc;
}
.history-table tbody tr.mastered td {
  background: #f0fdf4 !important;
}

.history-table .col-num,
.history-table .hi-num   { white-space: nowrap; color: #475569; }
.history-table .col-term,
.history-table .hi-term  { font-weight: 700; white-space: nowrap; }
.history-table .col-cnt,
.history-table .hi-correct,
.history-table .hi-wrong { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-table .hi-correct { color: #16a34a; font-weight: 600; }
.history-table .hi-wrong   { color: #dc2626; font-weight: 600; }
.history-table .bold { font-weight: 700; color: #0f172a; }

.history-table .hi-jp,
.history-table .hi-en {
  /* Let long sentences wrap, but cap width so they don't dominate. */
  max-width: 24em;
  word-break: break-word;
}

.history-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: #64748b;
  margin: 0;
}
.history-empty.hidden { display: none; }

@media (max-width: 700px) {
  .history-table { font-size: 0.8rem; }
  .history-table thead th { padding: 0.35rem 0.4rem; }
  .history-table tbody td { padding: 0.35rem 0.4rem; }
  .history-table .hi-jp,
  .history-table .hi-en { max-width: 16em; }
}

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
}
.login-form {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.login-form h1 { margin: 0; font-size: 1.4rem; text-align: center; }
.login-form label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 0.2rem;
}
.login-form input {
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}
.login-form button {
  background: #2563eb;
  color: #ffffff;
  border: 0;
  border-radius: 6px;
  padding: 0.7rem;
  font-size: 1rem;
  font-weight: 600;
}
.login-form .error { color: #dc2626; margin: 0; }

/* ---------- Celebration ---------- */
.celebration {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.celebration.hidden { display: none; }
.celebration-inner {
  background: #ffffff;
  border-radius: 16px;
  padding: 1.5rem 1.5rem 1.25rem;
  max-width: 360px;
  width: 90%;
  text-align: center;
  animation: pop 0.35s ease-out;
}
.celebration-emoji {
  font-size: 3rem;
  animation: bounce 1.2s ease infinite;
}
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
@keyframes bounce {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-8px); }
}
