:root {
  --bg-top: #060d1a;
  --bg-bottom: #0b1829;
  --panel: rgba(11, 24, 41, 0.9);
  --panel-soft: rgba(15, 30, 51, 0.92);
  --line: rgba(122, 184, 216, 0.28);
  --gold: #f0d060;
  --sky: #7ab8d8;
  --text: #f7fbff;
  --text-soft: #bfd4ea;
  --success: #67d38d;
  --danger: #ff6868;
  --muted: #6d7d92;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Noto Sans JP", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 15%, rgba(122, 184, 216, 0.16), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(240, 208, 96, 0.16), transparent 26%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.9), transparent 85%);
}

body.flash-wrong {
  animation: flash-wrong 0.5s ease-out;
}

@keyframes flash-wrong {
  0% {
    box-shadow: inset 0 0 0 rgba(255, 104, 104, 0);
  }
  50% {
    box-shadow: inset 0 0 0 100vmax rgba(255, 104, 104, 0.18);
  }
  100% {
    box-shadow: inset 0 0 0 rgba(255, 104, 104, 0);
  }
}

.app-shell {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 24px 14px 48px;
}

.screen {
  display: none;
  animation: fade-in 0.3s ease;
}

.screen.active {
  display: grid;
  gap: 16px;
}

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

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 18%),
    var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
}

.compact-panel {
  padding: 16px;
}

.hero-panel {
  padding: 28px 22px 24px;
  text-align: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--sky);
}

.eyebrow::before,
.eyebrow::after {
  content: "";
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-shadow: 0 0 20px rgba(240, 208, 96, 0.16);
}

h2 {
  font-size: 1.45rem;
  font-weight: 800;
}

h3 {
  font-size: 1.1rem;
  font-weight: 800;
}

.lead,
.section-head p,
.answer-label,
.result-accuracy,
.result-rank,
.status-box,
.hint-body,
.choice-sub,
.result-meta,
.result-answer,
.summary-chip span {
  color: var(--text-soft);
}

.lead {
  margin-top: 12px;
  line-height: 1.8;
  font-size: 0.98rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head p {
  margin-top: 6px;
  font-size: 0.92rem;
  line-height: 1.7;
}

.toggle-grid,
.mode-grid,
.choices-container,
.result-list {
  display: grid;
  gap: 12px;
}

.region-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.count-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mode-grid {
  grid-template-columns: 1fr;
}

.toggle-button,
.mode-button,
.choice-button,
.action-button {
  border: 1px solid transparent;
  border-radius: 18px;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease,
    opacity 0.18s ease,
    background 0.18s ease;
}

.toggle-button,
.mode-button,
.choice-button {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 22%),
    var(--panel-soft);
  border-color: rgba(122, 184, 216, 0.18);
}

.toggle-button:hover,
.mode-button:hover,
.choice-button:hover,
.action-button:hover {
  transform: translateY(-1px) scale(1.01);
  box-shadow:
    0 16px 32px rgba(0, 0, 0, 0.22),
    0 0 22px rgba(122, 184, 216, 0.14);
}

.toggle-button {
  min-height: 54px;
  padding: 14px 10px;
  font-size: 0.95rem;
  font-weight: 800;
}

.toggle-button.is-active,
.mode-button.is-active {
  border-color: rgba(240, 208, 96, 0.82);
  background:
    linear-gradient(180deg, rgba(240, 208, 96, 0.18), rgba(240, 208, 96, 0.04)),
    #142646;
  box-shadow: 0 0 0 1px rgba(240, 208, 96, 0.1);
}

.toggle-button.is-disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.mode-button {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  text-align: left;
}

.mode-emoji {
  font-size: 1.5rem;
  line-height: 1;
}

.mode-copy strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1rem;
}

.mode-copy span {
  display: block;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-soft);
}

.status-box {
  min-height: 54px;
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(122, 184, 216, 0.18);
  background: rgba(5, 18, 34, 0.8);
  line-height: 1.7;
  font-size: 0.95rem;
}

.status-box.success {
  color: #daf6e5;
  border-color: rgba(103, 211, 141, 0.35);
}

.status-box.error {
  color: #ffdede;
  border-color: rgba(255, 104, 104, 0.35);
}

.status-box.quiet {
  color: var(--text-soft);
}

.loading-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px dashed rgba(122, 184, 216, 0.2);
  color: var(--text-soft);
  font-size: 0.94rem;
}

.spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--gold);
  border-right-color: var(--sky);
  animation: spin 0.8s linear infinite;
}

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

.hidden {
  display: none !important;
}

.action-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.title-actions,
.result-actions {
  justify-content: center;
  margin-top: 14px;
}

.action-button {
  min-height: 54px;
  padding: 0 20px;
  font-weight: 800;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.2);
}

.action-button.primary {
  background: linear-gradient(180deg, #4560d8, #253b95);
  border-color: rgba(240, 208, 96, 0.4);
}

.action-button.secondary {
  background: linear-gradient(180deg, #1f3355, #13263f);
  border-color: rgba(122, 184, 216, 0.26);
}

.action-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.quiz-header-panel {
  padding-bottom: 18px;
}

.quiz-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(122, 184, 216, 0.18);
  background: rgba(12, 29, 51, 0.82);
}

.metric-card span,
.summary-chip span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--sky);
}

.metric-card strong,
.summary-chip strong {
  display: block;
  font-size: 1rem;
  font-weight: 800;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(19, 39, 66, 0.9);
  border: 1px solid rgba(122, 184, 216, 0.18);
  font-size: 0.85rem;
  font-weight: 700;
}

.progress-track {
  height: 12px;
  margin-top: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

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

.question-panel,
.answer-panel {
  display: grid;
  gap: 14px;
}

.question-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.question-content {
  min-height: 180px;
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 18px;
  border-radius: 22px;
  border: 1px solid rgba(240, 208, 96, 0.14);
  background: rgba(9, 23, 42, 0.72);
  text-align: center;
}

.prompt-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
}

.prompt-card {
  width: 100%;
  padding: 18px;
  border-radius: 20px;
  background: rgba(15, 32, 57, 0.94);
  border: 1px solid rgba(122, 184, 216, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.prompt-main {
  font-size: clamp(1.55rem, 6vw, 2.1rem);
  font-weight: 900;
  line-height: 1.35;
}

.prompt-sub {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--text-soft);
}

.stats-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 18px 12px;
  border-radius: 18px;
  border: 1px solid rgba(122, 184, 216, 0.14);
  background: rgba(15, 32, 57, 0.94);
}

.stat-card span {
  display: block;
  margin-bottom: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--sky);
}

.stat-card strong {
  display: block;
  font-size: 1.2rem;
  line-height: 1.35;
}

.hint-button {
  width: 100%;
  background: linear-gradient(180deg, #1f3c65, #18314f);
  border-color: rgba(240, 208, 96, 0.28);
}

.hint-panel {
  display: grid;
  gap: 10px;
  max-height: 0;
  padding: 0 16px;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid transparent;
  background: rgba(12, 29, 51, 0.78);
  opacity: 0;
  transition:
    max-height 0.3s ease,
    padding 0.3s ease,
    opacity 0.3s ease,
    border-color 0.3s ease;
}

.hint-panel.visible {
  max-height: 260px;
  padding: 16px;
  border-color: rgba(122, 184, 216, 0.2);
  opacity: 1;
}

.hint-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--gold);
}

.hint-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  line-height: 1.7;
  animation: slide-down 0.3s ease;
}

@keyframes slide-down {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.hint-region {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(240, 208, 96, 0.26);
  background: rgba(240, 208, 96, 0.08);
  font-weight: 800;
  color: var(--gold);
}

.choices-container {
  grid-template-columns: 1fr;
}

.choice-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  text-align: left;
}

.choice-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.choice-label {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.35;
}

.choice-sub {
  font-size: 0.85rem;
}

.choice-button.is-correct {
  background: linear-gradient(180deg, rgba(103, 211, 141, 0.24), rgba(31, 88, 53, 0.9));
  border-color: rgba(103, 211, 141, 0.56);
}

.choice-button.is-wrong {
  background: linear-gradient(180deg, rgba(255, 104, 104, 0.24), rgba(104, 25, 25, 0.9));
  border-color: rgba(255, 104, 104, 0.5);
}

.choice-button.is-muted {
  opacity: 0.45;
}

.choice-button:disabled {
  cursor: not-allowed;
}

.flag-media {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(23, 48, 81, 0.9), rgba(10, 22, 38, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.2);
}

.flag-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.flag-media.has-image .flag-fallback {
  display: none;
}

.flag-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.flag-media.large {
  width: 160px;
  height: 107px;
}

.flag-media.large .flag-fallback {
  font-size: 1.8rem;
}

.flag-media.small {
  width: 36px;
  height: 24px;
  border-radius: 8px;
  flex: 0 0 36px;
}

.flag-media.small .flag-fallback {
  font-size: 0.72rem;
}

.flag-media.hint {
  width: 120px;
  height: 80px;
}

.flag-media.hint .flag-fallback {
  font-size: 1.2rem;
}

.result-hero {
  text-align: center;
  display: grid;
  gap: 10px;
}

.score-display {
  font-size: clamp(2.3rem, 9vw, 3.6rem);
  font-weight: 900;
  color: var(--gold);
  line-height: 1.1;
  text-shadow: 0 0 22px rgba(240, 208, 96, 0.2);
}

.result-rank {
  font-size: 1rem;
  line-height: 1.7;
}

.result-summary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.summary-chip {
  padding: 14px 12px;
  border-radius: 18px;
  border: 1px solid rgba(122, 184, 216, 0.16);
  background: rgba(12, 29, 51, 0.82);
  text-align: center;
}

.result-list-panel h3 {
  margin-bottom: 14px;
}

.result-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.result-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(122, 184, 216, 0.14);
  background: rgba(12, 29, 51, 0.82);
}

.result-item.is-correct {
  border-color: rgba(103, 211, 141, 0.34);
}

.result-item.is-wrong {
  border-color: rgba(255, 104, 104, 0.26);
}

.result-name {
  font-weight: 800;
}

.result-meta,
.result-answer {
  font-size: 0.85rem;
  line-height: 1.6;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 800;
}

.result-badge.correct {
  color: #daf6e5;
  background: rgba(103, 211, 141, 0.14);
}

.result-badge.wrong {
  color: #ffe0e0;
  background: rgba(255, 104, 104, 0.14);
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 60;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  width: 10px;
  height: 18px;
  border-radius: 4px;
  background: var(--piece-color, var(--gold));
  opacity: 0;
  animation: confetti-fall 1.2s ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform:
      translate3d(var(--drift-x, 0), 115vh, 0)
      rotate(var(--spin, 480deg));
  }
}

@media (min-width: 768px) {
  .mode-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .question-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .hint-button {
    width: auto;
    min-width: 210px;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .panel {
    padding: 16px;
    border-radius: 24px;
  }

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

  .result-badge {
    grid-column: 2;
    justify-self: start;
  }
}
