:root {
  --background: #eff7ff;
  --surface: #ffffff;
  --primary: #5468ff;
  --primary-dark: #3f50db;
  --secondary: #eef0ff;
  --text: #26324a;
  --muted: #67738b;
  --border: #dce3ee;
  --success: #18864b;
  --success-light: #e5f7ed;
  --danger: #d53f4f;
  --danger-light: #ffebee;
  --warning: #ffb02e;
  --shadow: 0 18px 45px rgba(74, 96, 140, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, rgba(91, 208, 255, 0.22), transparent 32%),
    radial-gradient(circle at 90% 15%, rgba(255, 193, 91, 0.2), transparent 28%),
    var(--background);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  line-height: 1.6;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.app-card {
  position: relative;
  width: min(100%, 700px);
  min-height: 520px;
  padding: clamp(24px, 5vw, 48px);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.app-card::before {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 8px;
  content: "";
  background: linear-gradient(90deg, #5468ff, #48c6ef, #ffba49);
}

.app-badge {
  margin: 0 0 24px;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.screen {
  animation: fade-in 0.25s ease-out;
}

.screen[hidden],
[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  line-height: 1.3;
}

h1 {
  margin-bottom: 16px;
  font-size: clamp(2rem, 7vw, 3rem);
  text-align: center;
}

h2 {
  font-size: clamp(1.55rem, 5vw, 2.1rem);
}

.hero-icon {
  margin: 20px 0 8px;
  font-size: 4rem;
  text-align: center;
}

.lead {
  margin-bottom: 32px;
  color: var(--muted);
  font-size: 1.05rem;
  text-align: center;
}

.button-stack {
  display: grid;
  gap: 12px;
  max-width: 420px;
  margin: 0 auto;
}

.button-stack.compact {
  margin-top: 14px;
}

.button {
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  color: var(--text);
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.button:focus-visible,
.choice-button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(84, 104, 255, 0.35);
  outline-offset: 3px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.button-primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(84, 104, 255, 0.25);
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.button-secondary {
  color: var(--primary-dark);
  background: var(--secondary);
}

.quiz-home-button {
  margin-top: 12px;
}

.button-accent {
  color: #714800;
  background: #fff0c7;
}

.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.home-stats div {
  padding: 12px 8px;
  text-align: center;
  background: #f7f9fc;
  border-radius: 12px;
}

.home-stats span,
.home-stats strong {
  display: block;
}

.home-stats span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.quiz-settings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 22px;
  padding: 16px;
  background: #f7f9fc;
  border-radius: 16px;
}

.setting-field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.setting-field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 30px 8px 10px;
  color: var(--text);
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 10px;
}

.quiz-status {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
}

.quiz-status p {
  margin-bottom: 8px;
}

.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  margin-bottom: 8px;
  color: var(--primary-dark);
  font-size: 0.88rem;
  font-weight: 800;
}

.combo-badge {
  padding: 5px 10px;
  color: #8a4d00;
  background: #fff0c7;
  border-radius: 999px;
  animation: combo-pop 0.25s ease-out;
}

.progress-track {
  height: 10px;
  margin-bottom: 28px;
  overflow: hidden;
  background: #e9edf5;
  border-radius: 999px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #48c6ef);
  border-radius: inherit;
  transition: width 0.25s ease;
}

.question-text {
  min-height: 3.2em;
  margin-bottom: 24px;
}

.choices {
  display: grid;
  gap: 12px;
  margin-bottom: 22px;
}

.choice-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 12px 16px;
  color: var(--text);
  text-align: left;
  background: #f8faff;
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.choice-button:hover:not(:disabled) {
  background: #f0f3ff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

.choice-button:disabled {
  color: var(--text);
  cursor: default;
}

.choice-number {
  display: grid;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  color: #fff;
  background: var(--primary);
  border-radius: 50%;
  place-items: center;
  font-weight: 800;
}

.choice-button.correct {
  background: var(--success-light);
  border-color: var(--success);
}

.choice-button.correct .choice-number {
  background: var(--success);
}

.choice-button.incorrect {
  background: var(--danger-light);
  border-color: var(--danger);
}

.choice-button.incorrect .choice-number {
  background: var(--danger);
}

.answer-feedback {
  margin-bottom: 18px;
  padding: 16px;
  background: #f7f9fc;
  border-radius: 14px;
}

.answer-result {
  margin-bottom: 6px;
  font-size: 1.15rem;
  font-weight: 800;
}

.answer-result.correct-text {
  color: var(--success);
}

.answer-result.incorrect-text {
  color: var(--danger);
}

.answer-explanation {
  margin-bottom: 0;
}

.result-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 24px;
  color: var(--primary);
}

.result-score strong {
  font-size: 4rem;
  line-height: 1;
}

.result-score span {
  font-size: 1.4rem;
  font-weight: 800;
}

.title-badge {
  width: fit-content;
  margin: -8px auto 12px;
  padding: 7px 16px;
  color: #714800;
  background: linear-gradient(135deg, #fff0c7, #ffe19a);
  border-radius: 999px;
  font-weight: 900;
}

.result-comment {
  margin-bottom: 20px;
  color: var(--muted);
  text-align: center;
}

.result-details {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 0 0 28px;
}

.result-details div {
  padding: 16px;
  text-align: center;
  background: #f7f9fc;
  border-radius: 14px;
}

.result-details dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.result-details dd {
  margin: 4px 0 0;
  font-size: 1.2rem;
  font-weight: 800;
}

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

.score-form label {
  display: block;
  margin-bottom: 7px;
  font-weight: 700;
}

.score-form input {
  width: 100%;
  min-height: 50px;
  margin-bottom: 10px;
  padding: 10px 14px;
  color: var(--text);
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 12px;
}

.field-error {
  margin-bottom: 10px;
  color: var(--danger);
  font-size: 0.92rem;
}

.message {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  font-weight: 700;
}

.message-error {
  color: #a51e2d;
  background: var(--danger-light);
  border: 1px solid #f6bac1;
}

.message-success {
  color: #126638;
  background: var(--success-light);
  border: 1px solid #b3e5c7;
}

.message-info {
  color: #324b85;
  background: #edf3ff;
  border: 1px solid #c8d8ff;
}

.stats-note {
  margin-bottom: 18px;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 18px 10px;
  text-align: center;
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.stat-card span,
.stat-card strong {
  display: block;
}

.stat-card span {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.8rem;
}

.stat-card strong {
  color: var(--primary-dark);
  font-size: 1.2rem;
}

.insight-card {
  margin-bottom: 20px;
  padding: 18px;
  color: #714800;
  text-align: center;
  background: #fff8e8;
  border-radius: 14px;
}

.insight-card span,
.insight-card strong {
  display: block;
}

.insight-card span {
  margin-bottom: 6px;
  font-size: 0.85rem;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  color: var(--primary-dark);
  background: #f0f3ff;
  border-radius: 12px;
  font-weight: 700;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(84, 104, 255, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.section-heading span {
  font-size: 2rem;
}

.section-heading h2 {
  margin-bottom: 0;
}

.table-wrapper {
  margin-bottom: 20px;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-size: 0.85rem;
}

td:first-child {
  color: var(--primary-dark);
  font-weight: 800;
}

.empty-message {
  padding: 36px 12px;
  color: var(--muted);
  text-align: center;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes combo-pop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 0;
  }

  .app-card {
    min-height: 100vh;
    padding: 28px 18px;
    border-radius: 0;
  }

  .quiz-status {
    font-size: 0.92rem;
  }

  .result-details {
    grid-template-columns: 1fr;
  }

  .quiz-settings,
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .setting-field:first-child {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
