:root {
  --bg1: #fff7ed;
  --bg2: #e0f2fe;
  --panel: rgba(255,255,255,0.94);
  --text: #172033;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --danger: #ef4444;
  --danger-dark: #b91c1c;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 0%, #fde68a 0 10%, transparent 28%),
    radial-gradient(circle at 90% 20%, #bae6fd 0 12%, transparent 30%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  min-height: 100vh;
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  user-select: none;
}

.app {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 6px;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 5vw, 44px);
  letter-spacing: 0.02em;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.back-link { text-decoration: none; white-space: nowrap; }

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 700;
  font-size: clamp(13px, 2.5vw, 16px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 16px;
  margin: 14px 0;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.section-title h2,
h3 {
  margin: 0;
}

.section-title span,
.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 860px) {
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.sound-rows {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.sound-row {
  display: grid;
  grid-template-columns: 1fr 72px 72px;
  gap: 8px;
  align-items: center;
}

.sound-row input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 18px;
  font-weight: 800;
}

.sound-row input[type="color"] {
  width: 72px;
  height: 52px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: white;
}

textarea {
  width: 100%;
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  font-size: 18px;
  resize: vertical;
  background: #fff;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 900;
  margin: 8px 0 6px;
}

.sequence-length-control {
  margin: 10px 0 14px;
  padding: 12px;
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  background: #eff6ff;
}

.sequence-length-control label {
  margin-top: 0;
  color: #1e3a8a;
}

.sequence-length-control select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 2px solid #93c5fd;
  border-radius: 14px;
  background: white;
  color: #172554;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.sequence-length-control .hint {
  margin: 7px 0 0;
}

.sequence-length-control select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  outline-offset: 2px;
}

.option-box {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 12px;
  border-radius: 18px;
  background: #f8fafc;
  border: 1px solid var(--border);
}

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: #334155;
}

.check-label input {
  width: 20px;
  height: 20px;
}

.button-row,
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 900;
  transition: transform 0.08s, filter 0.12s;
}

button:active {
  transform: translateY(2px);
}

.primary-btn {
  background: var(--primary);
  color: white;
  font-size: 18px;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn,
.ghost-btn {
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid var(--border);
}

.ghost-btn {
  min-width: 76px;
}

.danger-btn {
  background: #fee2e2;
  color: var(--danger-dark);
  border: 1px solid #fecaca;
}

.success-btn {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.game-panel {
  overflow: hidden;
}

.stage {
  text-align: center;
}

.dino-group {
  display: inline-flex;
  gap: 6px;
  align-items: flex-end;
  justify-content: center;
  min-height: 86px;
  margin-bottom: 4px;
}

.dino {
  display: inline-block;
  font-size: clamp(42px, 10vw, 88px);
  line-height: 1;
  filter: drop-shadow(0 8px 8px rgba(15,23,42,0.15));
}

.dino2 {
  font-size: clamp(50px, 12vw, 110px);
}

.dino-group.celebrate .dino {
  animation: clap 0.75s ease-in-out infinite;
}

.dino-group.celebrate .dino2 {
  animation-delay: 0.1s;
}

.dino-group.celebrate .dino3 {
  animation-delay: 0.2s;
}

@keyframes clap {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  30% { transform: translateY(-16px) rotate(-8deg) scale(1.05); }
  60% { transform: translateY(-8px) rotate(8deg) scale(1.02); }
}

.feedback {
  font-size: clamp(28px, 7vw, 58px);
  font-weight: 1000;
  line-height: 1.15;
  min-height: 68px;
}

.sub-feedback {
  color: var(--muted);
  font-weight: 800;
  min-height: 28px;
}

.progress-wrap {
  max-width: 740px;
  margin: 16px auto;
}

.progress-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
  color: #334155;
  margin-bottom: 8px;
}

.progress-bar {
  height: 16px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #84cc16);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.teacher-answer {
  max-width: 740px;
  margin: 8px auto 14px;
  padding: 10px;
  border-radius: 18px;
  background: #fefce8;
  border: 1px solid #fde68a;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}

.teacher-chip,
.answer-chip {
  display: inline-flex;
  min-width: 42px;
  height: 42px;
  padding: 0 12px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: white;
  font-weight: 1000;
  text-shadow: 0 1px 3px rgba(0,0,0,.25);
}

.button-zone {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: clamp(12px, 3vw, 22px);
  max-width: 760px;
  margin: 16px auto;
}

@media (min-width: 760px) {
  .button-zone.three-or-more {
    grid-template-columns: repeat(3, 1fr);
  }
}

.sound-button {
  min-height: clamp(118px, 22vw, 190px);
  border-radius: 30px;
  color: white;
  font-size: clamp(38px, 9vw, 72px);
  font-weight: 1000;
  text-shadow: 0 3px 5px rgba(0,0,0,.25);
  border: 7px solid rgba(255,255,255,.75);
  box-shadow: 0 12px 0 rgba(15,23,42,.18);
  position: relative;
  overflow: hidden;
}

.sound-button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,.35), transparent 30%);
}

.sound-button:active {
  transform: translateY(7px);
  box-shadow: 0 5px 0 rgba(15,23,42,.18);
}

.control-row {
  justify-content: center;
}

.answer-area {
  margin-top: 14px;
}

.answer-area h3 {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 8px;
}

.answer-log {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 48px;
}

.answer-chip.wrong {
  outline: 5px solid #fecaca;
}

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

.record-card {
  padding: 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #f8fafc;
  text-align: center;
}

.record-card strong {
  display: block;
  font-size: clamp(26px, 6vw, 44px);
}

.record-card span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 900;
}

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

.confetti {
  position: absolute;
  top: -30px;
  width: 12px;
  height: 18px;
  border-radius: 5px;
  animation: fall 1.7s linear forwards;
}

.flower {
  position: absolute;
  top: -40px;
  font-size: 28px;
  animation: fall 1.9s linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(112vh) rotate(560deg);
    opacity: 0.25;
  }
}

.hidden {
  display: none !important;
}

@media (max-width: 520px) {
  .app {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  .section-title {
    display: block;
  }

  .sound-row {
    grid-template-columns: 1fr 64px 64px;
  }

  .sound-row input[type="color"] {
    width: 64px;
  }

  .button-zone {
    grid-template-columns: 1fr 1fr;
  }

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

  .panel {
    border-radius: 22px;
    padding: 12px;
  }
}
