:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #FF9900;
  --green: #3fb950;
  --red: #f85149;
  --btn-bg: #21262d;
  --btn-hover: #30363d;
  --radius: 8px;
}

[data-theme="froggy"] {
  --bg: #2d3436;
  --surface: #383e42;
  --border: #1a3a3a;
  --text: #e8f5e9;
  --text-muted: #a8b89f;
  --accent: #6b8e5f;
  --green: #6b8e5f;
  --red: #d97060;
  --btn-bg: #354239;
  --btn-hover: #445241;
  --btn-primary-bg: #8B3A62;
  --btn-primary-hover: #a84a76;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.5rem;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

header p {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card h2 {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

select, input[type="number"], input[type="text"] {
  width: 100%;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  appearance: none;
  -webkit-appearance: none;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row-narrow {
  grid-template-columns: 1fr;
  max-width: 50%;
}

.form-row-wide {
  max-width: 100%;
}

.btn {
  display: inline-block;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.1s, background 0.1s;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  width: 100%;
  text-align: center;
}

.btn-primary:hover { opacity: 0.85; }

[data-theme="froggy"] .btn-primary {
  background: var(--btn-primary-bg);
  color: var(--text);
}

[data-theme="froggy"] .btn-primary:hover {
  background: var(--btn-primary-hover);
  opacity: 1;
}

.btn-secondary {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-group {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn-group .btn { flex: 1; text-align: center; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }

.score-good { color: var(--green); font-weight: 600; }
.score-mid  { color: var(--accent); font-weight: 600; }
.score-bad  { color: var(--red); font-weight: 600; }

.progress-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 0.4rem;
}

.progress-bar-outer {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 1.5rem;
}

.progress-bar-inner {
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

.domain-badge {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  margin-bottom: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.question-text {
  font-size: 1.05rem;
  line-height: 1.65;
  margin-bottom: 1.5rem;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.85rem 1rem;
  cursor: pointer;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.5;
  transition: border-color 0.1s, background 0.1s;
  width: 100%;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--btn-hover);
}

.option-btn:disabled { cursor: default; }

.option-btn.correct {
  border-color: var(--green);
  background: rgba(63, 185, 80, 0.1);
}

.option-btn.incorrect {
  border-color: var(--red);
  background: rgba(248, 81, 73, 0.1);
}

.option-label {
  font-weight: 700;
  color: var(--text-muted);
  min-width: 1.2rem;
  flex-shrink: 0;
}

.explanation {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--btn-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--text-muted);
  display: none;
}

.explanation.visible { display: block; }

.next-row {
  margin-top: 1.25rem;
  text-align: right;
  display: none;
}

.next-row.visible { display: block; }

.next-row .btn { width: auto; }

.result-score {
  text-align: center;
  padding: 2rem 0 1.5rem;
}

.score-number {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1;
}

.score-detail {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.score-player {
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  margin-top: 0.65rem;
  overflow-wrap: anywhere;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.stat-box {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
  font-size: 0.875rem;
}

.theme-toggle-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#theme-toggle {
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-width: 6rem;
  min-height: 2.35rem;
  font-weight: 700;
}

.theme-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  flex: 0 0 1.35rem;
  font-size: 1.05rem;
  line-height: 1;
}

.theme-label {
  line-height: 1;
  white-space: nowrap;
}

header {
  position: relative;
}

header > div {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* ===== FROGGIFIED CHAOS THEME ===== */

[data-theme="chaos"] {
  --bg: #071012;
  --surface: rgba(8, 20, 22, 0.9);
  --border: rgba(80, 255, 178, 0.62);
  --text: #ecfff5;
  --text-muted: #a8e7da;
  --accent: #ff3b9d;
  --green: #50ff7a;
  --red: #ff4f7a;
  --btn-bg: rgba(9, 30, 31, 0.92);
  --btn-hover: rgba(22, 56, 52, 0.94);
  --btn-primary-bg: #d8ff39;
  --btn-primary-hover: #edff82;
  --radius: 6px;
}

@keyframes chaos-marquee-scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

@keyframes chaos-mascot-hop {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(-4deg); }
  45% { transform: translate3d(0, -10px, 0) rotate(3deg); }
}

@keyframes chaos-haze {
  0%, 100% { opacity: 0.42; transform: translate3d(0, 0, 0); }
  50% { opacity: 0.7; transform: translate3d(-12px, 8px, 0); }
}

#chaos-marquee {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2.25rem;
  overflow: hidden;
  z-index: 30;
  background: linear-gradient(90deg, rgba(216, 255, 57, 0.96), rgba(46, 255, 215, 0.96), rgba(255, 59, 157, 0.96));
  color: #071012;
  border-bottom: 1px solid rgba(236, 255, 245, 0.38);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
  white-space: nowrap;
}

#chaos-marquee[hidden] {
  display: none;
}

#chaos-marquee span {
  display: inline-block;
  min-width: 50%;
  padding: 0.58rem 2rem 0.5rem;
  font-family: 'Trebuchet MS', Verdana, sans-serif;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  animation: chaos-marquee-scroll 12s linear infinite;
}

#chaos-mascot {
  position: fixed;
  right: max(1rem, calc((100vw - 800px) / 2 - 5.5rem));
  bottom: 1rem;
  width: clamp(84px, 12vw, 138px);
  height: auto;
  z-index: 9;
  pointer-events: none;
  filter: drop-shadow(0 18px 22px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 18px rgba(80, 255, 122, 0.55));
  animation: chaos-mascot-hop 4.8s ease-in-out infinite;
}

#chaos-mascot[hidden] {
  display: none;
}

[data-theme="chaos"] body {
  background-color: #071012;
  background-image:
    linear-gradient(180deg, rgba(7, 16, 18, 0.36), rgba(7, 16, 18, 0.84)),
    url('assets/chaos-noise.png'),
    url('assets/chaos-swamp-bg-v2.png');
  background-attachment: fixed, fixed, fixed;
  background-position: center, center, center top;
  background-repeat: no-repeat, repeat, no-repeat;
  background-size: cover, 256px 256px, cover;
  overflow-x: hidden;
}

[data-theme="chaos"] body::before,
[data-theme="chaos"] body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
}

[data-theme="chaos"] body::before {
  z-index: 0;
  background:
    radial-gradient(circle at 16% 18%, rgba(216, 255, 57, 0.14), transparent 24rem),
    radial-gradient(circle at 83% 26%, rgba(255, 59, 157, 0.12), transparent 22rem),
    linear-gradient(90deg, rgba(46, 255, 215, 0.08), transparent 28%, rgba(80, 255, 122, 0.06));
  mix-blend-mode: screen;
  animation: chaos-haze 9s ease-in-out infinite;
}

[data-theme="chaos"] body::after {
  z-index: 1;
  background: repeating-linear-gradient(0deg, rgba(236, 255, 245, 0.05), rgba(236, 255, 245, 0.05) 1px, transparent 1px, transparent 5px);
  opacity: 0.2;
}

[data-theme="chaos"] .container {
  position: relative;
  z-index: 3;
  margin-top: 3.25rem;
}

[data-theme="chaos"] header h1 {
  color: #ecfff5;
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 800;
  text-shadow: 0 2px 14px rgba(80, 255, 122, 0.5), 0 0 1px #071012;
}

[data-theme="chaos"] header p {
  color: #b5fff0;
  font-weight: 700;
  text-shadow: 0 1px 10px rgba(46, 255, 215, 0.45);
}

[data-theme="chaos"] .card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(7, 18, 21, 0.94), rgba(10, 31, 31, 0.9));
  border: 1px solid rgba(139, 255, 191, 0.58);
  border-radius: 8px;
  box-shadow: 0 20px 54px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(236, 255, 245, 0.13);
  backdrop-filter: blur(7px) saturate(1.18);
}

[data-theme="chaos"] .card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(216, 255, 57, 0.08), transparent 36%, rgba(255, 59, 157, 0.08));
  pointer-events: none;
}

[data-theme="chaos"] .card > * {
  position: relative;
}

[data-theme="chaos"] .card h2,
[data-theme="chaos"] label,
[data-theme="chaos"] th,
[data-theme="chaos"] .stat-label,
[data-theme="chaos"] .progress-label {
  color: #9fffe5;
}

[data-theme="chaos"] .card h2 {
  letter-spacing: 0.08em;
}

[data-theme="chaos"] select,
[data-theme="chaos"] input[type="number"],
[data-theme="chaos"] input[type="text"],
[data-theme="chaos"] .option-btn,
[data-theme="chaos"] .stat-box,
[data-theme="chaos"] .explanation {
  background: rgba(5, 17, 19, 0.78);
  border-color: rgba(118, 255, 184, 0.54);
  color: #ecfff5;
  box-shadow: inset 0 1px 0 rgba(236, 255, 245, 0.06);
}

[data-theme="chaos"] select:focus,
[data-theme="chaos"] input:focus {
  border-color: #ff3b9d;
  box-shadow: 0 0 0 3px rgba(255, 59, 157, 0.22);
}

[data-theme="chaos"] .btn-primary {
  background: linear-gradient(90deg, #d8ff39, #55ffd5);
  color: #071012;
  border: 1px solid rgba(236, 255, 245, 0.42);
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(46, 255, 215, 0.22);
}

[data-theme="chaos"] .btn-primary:hover {
  background: linear-gradient(90deg, #edff82, #7fffe2);
  opacity: 1;
}

[data-theme="chaos"] .btn-secondary {
  background: rgba(5, 17, 19, 0.82);
  color: #ecfff5;
  border-color: rgba(118, 255, 184, 0.5);
}

[data-theme="chaos"] .btn-secondary:hover,
[data-theme="chaos"] .option-btn:hover:not(:disabled) {
  background: rgba(20, 54, 51, 0.9);
  border-color: #ff3b9d;
}

[data-theme="chaos"] .progress-bar-outer {
  background: rgba(236, 255, 245, 0.16);
}

[data-theme="chaos"] .progress-bar-inner {
  background: linear-gradient(90deg, #d8ff39, #55ffd5, #ff3b9d);
  box-shadow: 0 0 18px rgba(85, 255, 213, 0.55);
}

[data-theme="chaos"] .domain-badge {
  color: #d8ff39;
  border-color: rgba(216, 255, 57, 0.65);
  background: rgba(216, 255, 57, 0.08);
}

[data-theme="chaos"] .option-btn.correct {
  border-color: #50ff7a;
  background: rgba(80, 255, 122, 0.16);
}

[data-theme="chaos"] .option-btn.incorrect {
  border-color: #ff4f7a;
  background: rgba(255, 79, 122, 0.16);
}

[data-theme="chaos"] .explanation {
  border-left-color: #ff3b9d;
}

[data-theme="chaos"] td {
  color: #ecfff5;
  border-bottom-color: rgba(118, 255, 184, 0.22);
}

[data-theme="chaos"] .score-good,
[data-theme="chaos"] .stat-value { color: #50ff7a; }
[data-theme="chaos"] .score-mid { color: #55ffd5; }
[data-theme="chaos"] .score-bad { color: #ff4f7a; }

[data-theme="chaos"] .score-number {
  text-shadow: 0 0 26px rgba(80, 255, 122, 0.42);
}

[data-theme="chaos"] #theme-toggle {
  min-width: 3.2rem;
  color: #071012;
  background: #d8ff39;
  border-color: rgba(236, 255, 245, 0.55);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

@media (max-width: 680px) {
  [data-theme="chaos"] .container {
    margin-top: 3rem;
  }

  #chaos-marquee {
    height: 2rem;
  }

  #chaos-marquee span {
    padding: 0.5rem 1rem 0.44rem;
    font-size: 0.66rem;
  }

  #chaos-mascot {
    width: 82px;
    right: 0.4rem;
    bottom: 0.35rem;
    opacity: 0.72;
  }

  [data-theme="chaos"] header > div {
    gap: 0.75rem;
  }

  [data-theme="chaos"] .card {
    border-radius: 7px;
  }
}
