@import url('https://fonts.googleapis.com/css2?family=Gowun+Batang:wght@400;700&family=Black+Han+Sans&display=swap');

:root {
  color-scheme: light;
  font-family: "Jua", "Pretendard", "Noto Sans KR", sans-serif;
  --font-body: "Jua", "Pretendard", "Noto Sans KR", sans-serif;
  --font-ui: "Black Han Sans", "Jua", "Pretendard", "Noto Sans KR", sans-serif;
  --bg: #fdf1d3;
  --card: #fff7e6;
  --text: #1f1b16;
  --muted: #6b5f52;
  --accent: #ff3d00;
  --accent-2: #00d4ff;
  --accent-3: #ffcc00;
  --danger: #ef4444;
  --success: #22c55e;
  --border: #1f1b16;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  font-weight: 800;
  font-size: 18px;
  font-family: var(--font-ui);
}

main {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
  min-height: calc(100vh - 72px);
}

section.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.04);
}

.quiz-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 12px;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
}

.quiz-card.no-question {
  overflow: hidden;
}

.quiz-card.no-question .prompt {
  margin: 4px 0;
}

.quiz-grid.multi .quiz-card.player-tone-1 {
  border-color: #fca5a5;
  background: #fff1f2;
  border-width: 2px;
}

.quiz-grid.multi .quiz-card.player-tone-2 {
  border-color: #93c5fd;
  background: #eff6ff;
  border-width: 2px;
}

.quiz-grid.multi .quiz-card.player-tone-3 {
  border-color: #fde68a;
  background: #fffbeb;
  border-width: 2px;
}

.quiz-grid.multi .quiz-card.player-tone-4 {
  border-color: #86efac;
  background: #f0fdf4;
  border-width: 2px;
}

.quiz-grid.multi .quiz-card.player-tone-5 {
  border-color: #5eead4;
  background: #f0fdfa;
  border-width: 2px;
}

.quiz-grid.multi .quiz-card.player-tone-6 {
  border-color: #f9a8d4;
  background: #fdf2f8;
  border-width: 2px;
}

.quiz-grid.face-to-face .quiz-card.face-flip {
  transform: rotate(180deg);
  transform-origin: center;
}

.quiz-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(var(--player-cols, 1), minmax(0, 1fr));
  align-content: stretch;
  grid-template-rows: repeat(var(--player-rows, 1), minmax(0, 1fr));
  overflow: hidden;
}

.player-tag {
  padding: 4px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #0f172a;
  font-weight: 700;
  font-size: 11px;
}

.player-summary {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.quiz-card.player-complete .choices {
  opacity: 0.6;
  pointer-events: none;
}

section.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
}

.settings-grid {
  display: grid;
  gap: 16px;
}

.settings-block {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 12px;
}

.settings-block-title {
  font-weight: 800;
  font-size: 14px;
  color: var(--text);
}

.settings-block-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.group-names {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 8px;
}

.group-names-actions {
  display: flex;
  justify-content: flex-start;
}

.name-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.name-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid #f1d4b0;
  box-shadow: 0 4px 0 rgba(146, 92, 28, 0.18);
  font-size: 12px;
  font-weight: 700;
}

.name-chip button {
  border: none;
  background: #ffcf9b;
  color: #7a3b00;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
  line-height: 1;
}

.settings-note {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 600;
}

.settings-block .settings-note {
  margin-top: 4px;
}

.settings-block .custom-panel,
.settings-block .type-grid,
.settings-block .type-confirm {
  grid-column: 1 / -1;
}

.settings-block .group-names {
  grid-column: 1 / -1;
}

.tone-blue {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.tone-purple {
  border-color: #ddd6fe;
  background: #f5f3ff;
}

.tone-teal {
  border-color: #99f6e4;
  background: #f0fdfa;
}

.tone-amber {
  border-color: #fde68a;
  background: #fffbeb;
}

.tone-green {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.tone-rose {
  border-color: #fecdd3;
  background: #fff1f2;
}

.tone-orange {
  border-color: #fed7aa;
  background: #fff7ed;
}


.mode-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mode-btn {
  border-radius: 14px;
  border: 2px solid #f1d4b0;
  background: #fff;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(146, 92, 28, 0.18);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, filter 0.2s ease;
  position: relative;
  overflow: hidden;
}

.mode-btn:hover {
  transform: translateY(-2px) scale(1.02);
}

.mode-btn:active {
  transform: translateY(3px) scale(0.98);
}

.mode-btn.is-active {
  background: linear-gradient(180deg, #ffd49b, #ffb56a);
  border-color: #f59e0b;
  box-shadow: 0 6px 0 rgba(166, 76, 0, 0.35);
  color: #7a3b00;
}

.mode-help {
  font-size: 12px;
  font-weight: 700;
  color: #8b5a2b;
}

.mode-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.mode-btn:disabled,
.sub-toggle:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.2);
  box-shadow: none;
}

@keyframes arcadePulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}


.custom-ids {
  grid-column: 1 / -1;
}

.custom-ids textarea {
  min-height: 84px;
}

.type-confirm {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.confirm-status {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.confirm-status.ready {
  color: #16a34a;
}

.custom-panel {
  grid-column: 1 / -1;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #f8fafc;
  display: grid;
  gap: 12px;
}

.custom-panel.hidden {
  display: none;
}

.custom-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.custom-count {
  display: flex;
  align-items: center;
  gap: 6px;
}

.custom-count label {
  margin: 0;
}

.custom-count input {
  width: 80px;
}

.custom-list {
  display: grid;
  gap: 12px;
}

.custom-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 8px;
}

.custom-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.custom-group-list {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.custom-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  background: #f8fafc;
  font-size: 11px;
}

.custom-item input {
  width: auto;
}

.custom-item img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.custom-item .custom-text {
  display: grid;
  gap: 2px;
}

.custom-item .custom-title {
  font-weight: 700;
  color: var(--text);
}

.custom-item .custom-sub {
  color: var(--muted);
  font-size: 10px;
}

.preset-summary {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

.preset-summary ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.settings-group {
  grid-column: 1 / -1;
  background: #f1f5f9;
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.group-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.group-note {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.type-grid {
  grid-column: 1 / -1;
  display: grid;
  gap: 16px;
}

.type-section {
  display: grid;
  gap: 10px;
}

.type-section-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.type-section-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.type-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.04);
}

.type-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}

.type-desc {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.preview-toggle {
  align-self: flex-start;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.type-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.type-card .type-preview {
  display: none;
}

.type-card.preview-open .type-preview {
  display: grid;
}

.type-row label {
  display: inline;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  min-width: 52px;
}

.type-row select,
.type-row input {
  flex: 1;
}

.type-preview {
  border-radius: 12px;
  border: 1px dashed var(--border);
  padding: 10px;
  background: #f8fafc;
  display: grid;
  gap: 8px;
}

.preview-question {
  display: grid;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.preview-question img {
  width: 100%;
  height: 120px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.preview-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.preview-choices img {
  width: 100%;
  height: 64px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.preview-choices img.hidden {
  display: none;
}

.type-preview.no-question .preview-question {
  display: none;
}

.preset-area {
  margin-top: 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preset-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#basic-list {
  margin-bottom: 12px;
  gap: 14px;
}

.preset-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.preset-btn.preset-hero {
  flex: 1 1 260px;
  min-height: 76px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 2px solid #c7d2fe;
  background: linear-gradient(135deg, #eef2ff, #f8fafc);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.12);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  font-weight: 800;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.preset-btn.preset-hero:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 32px rgba(37, 99, 235, 0.18);
}

.preset-hero-title {
  font-size: 16px;
  color: #1e3a8a;
  font-weight: 800;
}

.preset-hero-sub {
  font-size: 12px;
  color: #64748b;
  font-weight: 700;
}

.advanced-toggle {
  margin-top: 4px;
  align-self: flex-start;
}

.name-manage-toggle {
  margin-top: 6px;
  align-self: flex-start;
}

.advanced-settings.hidden {
  display: none;
}

.basic-field.hidden {
  display: none;
}
.sub-toggle {
  align-self: flex-start;
}

.type-grid.hidden {
  display: none;
}

.preset-btn span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.empty-note {
  font-size: 12px;
  color: var(--muted);
}

label {
  font-size: 12px;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

input, select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
}

textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;
  color: var(--text);
  background: #f8fafc;
}

button.primary {
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button {
  font-family: inherit;
  letter-spacing: 0.2px;
}

button,
.choice-btn,
.preset-btn,
.mode-btn {
  font-family: var(--font-ui);
}

/* === Korean Historical Game Theme === */
:root {
  --font-body: "Gowun Batang", "Noto Serif KR", serif;
  --font-ui: "Black Han Sans", "Gowun Batang", serif;
  --bg: #f2e4cf;
  --card: #fff6e6;
  --text: #2a1b12;
  --muted: #6c5a4b;
  --accent: #b3281e;
  --accent-2: #0f766e;
  --accent-3: #c7a34a;
  --border: #2b211a;
  --ink: #2a1b12;
  --wood: #9b6a43;
  --jade: #0f766e;
  --dancheong-red: #b91c1c;
  --dancheong-blue: #1d4ed8;
  --dancheong-green: #0f766e;
  --dancheong-yellow: #eab308;
}

body {
  font-family: var(--font-body);
  background:
    /* hanok wall lattice */
    linear-gradient(90deg, rgba(90, 63, 40, 0.12) 0 2px, transparent 2px 18px),
    linear-gradient(rgba(90, 63, 40, 0.12) 0 2px, transparent 2px 18px),
    /* subtle paper fiber */
    repeating-linear-gradient(45deg, rgba(0,0,0,0.035) 0 1px, transparent 1px 9px),
    /* dancheong color wash */
    radial-gradient(circle at 12% 18%, rgba(15, 118, 110, 0.2), transparent 42%),
    radial-gradient(circle at 85% 12%, rgba(185, 28, 28, 0.22), transparent 40%),
    radial-gradient(circle at 30% 85%, rgba(234, 179, 8, 0.2), transparent 42%),
    var(--bg);
}

header {
  font-family: var(--font-ui);
  font-size: 24px;
  letter-spacing: 1.2px;
  background: linear-gradient(90deg, #fff1d6, #fbe4c0);
  border-bottom: 4px solid var(--border);
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
}

header::after {
  content: "";
  display: block;
  height: 8px;
  margin-top: 10px;
  background: repeating-linear-gradient(
    90deg,
    var(--dancheong-red) 0 280px,
    var(--dancheong-blue) 280px 560px,
    var(--dancheong-green) 560px 840px,
    var(--dancheong-yellow) 840px 1120px
  );
  border-radius: 999px;
  opacity: 0.85;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5),
    0 3px 0 rgba(43, 33, 26, 0.4);
}

section.card {
  position: relative;
  border: 4px solid var(--border);
  background: var(--card);
  background-image:
    linear-gradient(90deg, rgba(58, 42, 31, 0.08) 0 1px, transparent 1px 12px),
    linear-gradient(rgba(58, 42, 31, 0.08) 0 1px, transparent 1px 12px),
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.7), transparent 45%),
    radial-gradient(circle at 80% 25%, rgba(255,255,255,0.5), transparent 45%);
  box-shadow:
    0 8px 0 var(--border),
    0 18px 28px rgba(0, 0, 0, 0.25);
}

section.card::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px dashed rgba(58, 42, 31, 0.35);
  border-radius: 16px;
  pointer-events: none;
}

.settings-block {
  border-width: 3px;
  border-color: var(--border);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.85);
}

.settings-block-title,
.group-title,
.prompt,
.quiz-header {
  font-family: var(--font-ui);
  letter-spacing: 0.4px;
}

.preset-btn {
  border: 3px solid var(--border);
  background: linear-gradient(180deg, #fff7e6, #f5dcc0);
  box-shadow: 0 6px 0 var(--border), 0 14px 22px rgba(0, 0, 0, 0.18);
  position: relative;
  overflow: hidden;
}

.preset-btn.preset-hero {
  background: linear-gradient(135deg, #ffd8a8, #ff9d5c);
  border: 4px solid var(--border);
  color: var(--ink);
  box-shadow: 0 10px 0 var(--border), 0 22px 32px rgba(0, 0, 0, 0.25);
  animation: hanPulse 3s ease-in-out infinite;
  position: relative;
  overflow: hidden;
}

.preset-btn.preset-hero::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px dashed rgba(42, 27, 18, 0.5);
  border-radius: inherit;
}

.preset-btn::after,
button.primary::after,
button.secondary::after,
.mode-btn::after,
.setting-button::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: inherit;
  padding: 2px;
  background-image: repeating-linear-gradient(
      90deg,
      rgba(185, 28, 28, 0.55) 0 8px,
      rgba(15, 118, 110, 0.55) 8px 16px,
      rgba(234, 179, 8, 0.55) 16px 24px,
      rgba(29, 78, 216, 0.55) 24px 32px
    );
  opacity: 0.35;
  pointer-events: none;
  -webkit-mask: linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.preset-hero-title {
  font-size: 20px;
  color: #3b2314;
}

.preset-hero-sub {
  color: #6e4a2d;
}

.primary,
button.primary {
  font-family: var(--font-ui);
  background: linear-gradient(180deg, #2fa79b, #0f766e);
  color: #fef3c7;
  border: 3px solid var(--border);
  box-shadow: 0 6px 0 var(--border), 0 16px 22px rgba(0, 0, 0, 0.25);
  position: relative;
  overflow: hidden;
}

.primary:active,
button.primary:active {
  transform: translateY(4px) scale(0.97);
  box-shadow: 0 2px 0 var(--border), 0 10px 18px rgba(0, 0, 0, 0.2);
  background: linear-gradient(180deg, #1c8a84, #0d5d58);
}

button.secondary,
.secondary {
  font-family: var(--font-ui);
  background: linear-gradient(180deg, #fff0d6, #e8c7a5);
  border: 3px solid var(--border);
  box-shadow: 0 5px 0 var(--border);
  position: relative;
  overflow: hidden;
}

.quiz-header {
  background: #fff2d9;
  border: 3px solid var(--border);
}

.question-frame {
  border: 4px dashed var(--border);
  background: #fff8ec;
}

.choice-btn {
  border: 3px solid var(--border);
  box-shadow: 0 7px 0 var(--border), 0 14px 20px rgba(0, 0, 0, 0.2);
}

.choice-btn::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: inherit;
  padding: 2px;
  background-image: repeating-linear-gradient(
      90deg,
      rgba(185, 28, 28, 0.4) 0 8px,
      rgba(15, 118, 110, 0.4) 8px 16px,
      rgba(234, 179, 8, 0.4) 16px 24px,
      rgba(29, 78, 216, 0.4) 24px 32px
    );
  opacity: 0.25;
  pointer-events: none;
  -webkit-mask: linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.choice-btn::after {
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.45), transparent 55%);
}

.choice-btn.correct {
  border-width: 6px;
  border-color: #15803d;
  box-shadow: 0 0 0 6px rgba(21, 128, 61, 0.3), 0 12px 20px rgba(21, 128, 61, 0.25);
}

.choice-btn.wrong {
  border-width: 6px;
  border-color: #b91c1c;
  box-shadow: 0 0 0 6px rgba(185, 28, 28, 0.3), 0 12px 20px rgba(185, 28, 28, 0.25);
}

.choice-badge {
  border: 3px solid var(--border);
  background: linear-gradient(180deg, #f7e6a1, #e4b860);
  color: var(--ink);
}

.choice-color-1 { background: linear-gradient(180deg, #f6c1b0, #e59a86); }
.choice-color-2 { background: linear-gradient(180deg, #b3d9e8, #7fb7d2); }
.choice-color-3 { background: linear-gradient(180deg, #f6e3a2, #e3c96b); }
.choice-color-4 { background: linear-gradient(180deg, #c6e8c5, #8fcd97); }

input, select, textarea {
  border: 3px solid var(--border);
  background: linear-gradient(180deg, #fff5e0, #f0d5b5);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.9), 0 3px 0 rgba(42, 27, 18, 0.18);
}

.modal-card {
  border: 3px solid var(--border);
  background: #fff6e6;
}

.name-chip {
  border: 2px solid var(--border);
  box-shadow: 0 4px 0 var(--border);
}

@keyframes hanPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.quiz-header {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.quiz-header strong {
  color: var(--text);
}

.prompt {
  font-size: 16px;
  font-weight: 700;
  margin: 6px 0;
}

.question-frame {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  flex: 1 1 0;
  position: relative;
}

.question-frame img {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
}

.question-zoom-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.choices {
  display: grid;
  grid-template-columns: repeat(var(--choice-cols, 2), minmax(0, 1fr));
  gap: 8px;
  margin-top: 0;
  align-content: stretch;
  flex: 1 1 0;
  min-height: 0;
}

.choices.structured-choices {
  display: block;
  grid-template-columns: none;
  align-content: initial;
  flex: initial;
  min-height: initial;
}

.choice-btn {
  --badge-size: 22px;
  --badge-pad: 6px;
  border: 2px solid transparent;
  background: #fff;
  border-radius: 12px;
  padding: calc(var(--badge-size) + var(--badge-pad) * 2) 8px 8px calc(var(--badge-size) + var(--badge-pad) * 2);
  cursor: pointer;
  transition: 0.2s ease;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.zoom-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
}

.zoom-modal.hidden {
  display: none;
}

.zoom-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}

.zoom-content {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  max-width: min(92vw, 1200px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
}

.zoom-close {
  align-self: flex-end;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

#zoom-img {
  width: 100%;
  height: 100%;
  max-height: 80vh;
  object-fit: contain;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 220;
  display: grid;
  place-items: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  position: relative;
  z-index: 1;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  width: min(92vw, 360px);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.modal-card p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.modal-form {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.modal-form label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.modal-form input,
.modal-form select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}

#basic-modal .modal-card {
  width: min(92vw, 560px);
  max-height: 88vh;
  overflow: hidden;
}

#basic-modal .modal-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 14px;
  row-gap: 12px;
  max-height: 52vh;
  overflow: auto;
  padding-right: 6px;
}

#basic-modal .modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#basic-modal .modal-field.span-2 {
  grid-column: span 2;
}

@media (max-width: 720px) {
  #basic-modal .modal-card {
    width: min(92vw, 420px);
  }
  #basic-modal .modal-form {
    grid-template-columns: 1fr;
    max-height: 60vh;
  }
  #basic-modal .modal-field.span-2 {
    grid-column: auto;
  }
}

#name-modal .modal-card {
  width: min(92vw, 520px);
  max-height: 88vh;
  overflow: hidden;
}

#name-modal .modal-form {
  max-height: 60vh;
  overflow: auto;
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.choice-badge {
  position: absolute;
  top: var(--badge-pad);
  left: var(--badge-pad);
  width: var(--badge-size);
  height: var(--badge-size);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
}

.choice-color-1 { background: #fde2e4; }
.choice-color-2 { background: #dbeafe; }
.choice-color-3 { background: #fef9c3; }
.choice-color-4 { background: #dcfce7; }

.choice-btn img {
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
}

.choice-btn:hover {
  border-color: #cbd5f5;
}

.choice-btn.correct {
  border-color: var(--success);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.1);
}

.choice-btn.wrong {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.08);
}

.hidden {
  display: none;
}

.feedback {
  margin-top: 12px;
  font-weight: 700;
  font-size: 28px;
}

/* === Arcade UI === */

body {
  background:
    repeating-linear-gradient(45deg, rgba(255, 207, 107, 0.25) 0 14px, rgba(255, 255, 255, 0) 14px 28px),
    radial-gradient(circle at 10% 15%, rgba(255, 98, 0, 0.22), transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(0, 212, 255, 0.2), transparent 38%),
    radial-gradient(circle at 30% 85%, rgba(255, 205, 0, 0.2), transparent 42%),
    var(--bg);
}

header {
  font-size: 24px;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ffe4a6, #fff7dd);
  border-bottom: 4px solid #1f1b16;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
}

section.card {
  border: 4px solid #1f1b16;
  border-radius: 22px;
  background: var(--card);
  background-image:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.7), transparent 45%),
    radial-gradient(circle at 80% 25%, rgba(255,255,255,0.5), transparent 45%);
  box-shadow:
    0 8px 0 #1f1b16,
    0 18px 28px rgba(0, 0, 0, 0.2);
}

.settings-block {
  border-width: 3px;
  border-color: #1f1b16;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.8);
}

.preset-btn {
  border-radius: 999px;
  font-family: var(--font-ui);
  background: #fff;
  border: 3px solid #1f1b16;
  box-shadow: 0 6px 0 #1f1b16, 0 14px 22px rgba(0, 0, 0, 0.14);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, filter 0.2s ease;
  font-size: 18px;
  padding: 9px 18px;
  gap: 9px;
}

.preset-btn:hover {
  transform: translateY(-2px) scale(1.02);
  filter: brightness(1.03);
  box-shadow: 0 8px 0 rgba(146, 92, 28, 0.2), 0 18px 28px rgba(0, 0, 0, 0.12);
}

.preset-btn:active {
  transform: translateY(4px) scale(0.97);
  box-shadow: 0 2px 0 #1f1b16, 0 8px 14px rgba(0, 0, 0, 0.14);
  background: #ffe5b1;
}

.preset-btn:focus-visible,
button.primary:focus-visible,
button.secondary:focus-visible,
.choice-btn:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.6);
  outline-offset: 2px;
}

.preset-btn.preset-hero {
  border: 4px solid #1f1b16;
  background: linear-gradient(135deg, #ffd24a, #ff8b00);
  color: #1f1b16;
  box-shadow: 0 10px 0 #1f1b16, 0 22px 30px rgba(0, 0, 0, 0.2);
  animation: arcadePulse 2.8s ease-in-out infinite;
  min-height: 114px;
  padding: 24px 27px;
  gap: 9px;
}

.preset-btn.preset-hero:hover {
  animation-play-state: paused;
}

.preset-hero-title {
  color: #1f1b16;
  font-size: 36px;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}

.preset-hero-sub {
  color: #4b2b12;
  font-size: 24px;
}

.preset-btn span {
  font-size: 16px;
}

.primary,
button.primary {
  font-family: var(--font-ui);
  background: linear-gradient(180deg, #00d4ff, #008bff);
  color: #0b1b2b;
  border: 3px solid #1f1b16;
  border-radius: 14px;
  box-shadow: 0 6px 0 #1f1b16, 0 16px 22px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.primary:hover,
button.primary:hover {
  transform: translateY(-2px) scale(1.02);
  filter: brightness(1.05);
}

.primary:active,
button.primary:active {
  transform: translateY(4px) scale(0.97);
  box-shadow: 0 2px 0 #1f1b16, 0 10px 18px rgba(0, 0, 0, 0.2);
  background: linear-gradient(180deg, #00b8ff, #0074e9);
}

button.secondary,
.secondary {
  font-family: var(--font-ui);
  background: linear-gradient(180deg, #fff5f5, #ffd5c2);
  border: 3px solid #1f1b16;
  border-radius: 12px;
  box-shadow: 0 5px 0 #1f1b16;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

button.secondary:hover,
.secondary:hover {
  transform: translateY(-2px) scale(1.02);
  filter: brightness(1.02);
}

button.secondary:active,
.secondary:active {
  transform: translateY(3px) scale(0.98);
  box-shadow: 0 3px 0 rgba(146, 92, 28, 0.2);
  background: #ffe7c7;
}

.quiz-header {
  font-family: var(--font-ui);
  background: #fff1c2;
  border: 3px solid #1f1b16;
  padding: 8px 10px;
  border-radius: 14px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.9);
}

.question-frame {
  border: 4px dashed #1f1b16;
  background: #fffbe8;
  box-shadow: inset 0 0 0 2px rgba(255, 231, 199, 0.9);
}

.choices {
  gap: 10px;
}

.choice-btn {
  border-radius: 16px;
  border: 3px solid #1f1b16;
  box-shadow: 0 7px 0 #1f1b16, 0 14px 20px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, filter 0.18s ease;
  overflow: hidden;
}

.choice-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(255,255,255,0.35), transparent 50%);
  opacity: 0.6;
  pointer-events: none;
}

.choice-btn:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 9px 0 #1f1b16, 0 22px 30px rgba(0, 0, 0, 0.2);
  filter: brightness(1.05);
}

.choice-btn:active {
  transform: translateY(4px) scale(0.96);
  box-shadow: 0 3px 0 #1f1b16, 0 12px 18px rgba(0, 0, 0, 0.18);
  filter: saturate(1.2);
}

.choice-badge {
  border: 3px solid #1f1b16;
  background: linear-gradient(180deg, #ffec9b, #ffc533);
  color: #1f1b16;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

.choice-color-1 { background: linear-gradient(180deg, #ffb3c7, #ff7a99); }
.choice-color-2 { background: linear-gradient(180deg, #8de1ff, #3bb6ff); }
.choice-color-3 { background: linear-gradient(180deg, #ffe48a, #ffbe2e); }
.choice-color-4 { background: linear-gradient(180deg, #9bffb8, #3ee78b); }

.choice-btn.correct {
  border-width: 6px;
  border-color: #22c55e;
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.25), 0 10px 22px rgba(34, 197, 94, 0.2);
}

.choice-btn.wrong {
  border-width: 6px;
  border-color: #ef4444;
  box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.25), 0 10px 22px rgba(239, 68, 68, 0.2);
}

.feedback.success {
  color: #0f9d58;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}

.feedback.fail {
  color: #ef4444;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.7);
}

input, select, textarea {
  border: 3px solid #1f1b16;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff7e6, #ffd9a1);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.9), 0 3px 0 rgba(31, 27, 22, 0.18);
  font-weight: 700;
  font-family: var(--font-body);
}

.csv-upload {
  border: 3px dashed #1f1b16;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #fff8eb, #ffe8bf);
}

.csv-upload-header {
  font-family: var(--font-ui);
  font-size: 16px;
  margin-bottom: 6px;
}

.csv-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.csv-upload-status {
  margin-top: 8px;
  min-height: 20px;
  font-weight: 700;
  font-size: 13px;
}

.csv-upload-status.success {
  color: #0f9d58;
}

.csv-upload-status.fail {
  color: #ef4444;
}

.csv-upload-status.warn {
  color: #a16207;
}

.custom-panel.csv-loaded .custom-actions,
.custom-panel.csv-loaded .custom-list {
  opacity: 0.55;
}

.mode-banner {
  margin: 8px 0 12px;
  border: 3px solid #1f1b16;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff6d9, #f5cf6d);
  color: #3b2a16;
  font-weight: 900;
  padding: 10px 12px;
}

body.csv-tool-mode #basic-list,
body.csv-tool-mode #name-manage-toggle,
body.csv-tool-mode #mode-block,
body.csv-tool-mode #type-toggle,
body.csv-tool-mode #type-grid,
body.csv-tool-mode .custom-actions,
body.csv-tool-mode #custom-list {
  display: none !important;
}

.choice-btn.choice-btn-text {
  padding: 38px 14px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.choice-text {
  display: block;
  font-size: clamp(16px, 2vw, 24px);
  line-height: 1.35;
  font-weight: 800;
  color: #1f1b16;
  text-align: center;
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.short-answer-widget {
  display: grid;
  gap: 10px;
  border: 3px solid #1f1b16;
  border-radius: 14px;
  background: linear-gradient(180deg, #fffaf0, #ffe7be);
  padding: 12px;
}

.short-answer-desc {
  font-weight: 800;
  color: #4b3a2a;
  font-size: 14px;
}

.short-answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.short-answer-input {
  width: 100%;
  min-height: 46px;
  border: 3px solid #1f1b16;
  border-radius: 12px;
  background: #fff;
  padding: 8px 10px;
  font-size: 16px;
  font-weight: 700;
}

.short-answer-input:focus {
  outline: 3px solid rgba(37, 99, 235, 0.25);
}

.short-answer-submit {
  min-width: 88px;
}

textarea {
  background: #fffaf3;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #f59e0b 50%),
    linear-gradient(135deg, #f59e0b 50%, transparent 50%),
    linear-gradient(to right, transparent, transparent);
  background-position:
    calc(100% - 18px) 55%,
    calc(100% - 12px) 55%,
    calc(100% - 2.5rem) 0.2rem;
  background-size: 6px 6px, 6px 6px, 2.5rem 2.5rem;
  background-repeat: no-repeat;
}

.feedback.success {
  color: var(--success);
}

.feedback.fail {
  color: var(--danger);
}

.summary {
  font-size: 16px;
  font-weight: 700;
}

.result-actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-actions .secondary {
  min-height: 44px;
  padding: 8px 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.rank-section {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.rank-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.rank-list {
  display: grid;
  gap: 6px;
}

.rank-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f8fafc;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
}

.rank-item .rank-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rank-badge {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #e2e8f0;
  color: #0f172a;
  font-size: 12px;
  font-weight: 800;
}

.rank-item.rank-1 .rank-badge { background: #fcd34d; }
.rank-item.rank-2 .rank-badge { background: #cbd5f5; }
.rank-item.rank-3 .rank-badge { background: #fdba74; }

.retry-area {
  margin-top: 16px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: #f8fafc;
}

.retry-area h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.retry-list {
  display: grid;
  gap: 8px;
}

.retry-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.retry-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.retry-actions {
  display: flex;
  gap: 8px;
}

.retry-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.timer {
  font-weight: 700;
  color: var(--accent);
}

.pvam-widget {
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.pvam-header {
  display: grid;
  gap: 4px;
}

.pvam-formula {
  font-weight: 800;
  font-size: 18px;
  color: var(--text);
}

.pvam-decomp {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.pvam-grid {
  display: grid;
  grid-template-columns: 40px repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.pvam-axis {
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
  color: #0f172a;
  min-height: 40px;
}

.pvam-axis-corner {
  background: #eef2ff;
}

.pvam-cell {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 6px;
  align-content: start;
  min-height: 88px;
}

.pvam-cell-expr {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.pvam-input,
.pvam-static {
  width: 100%;
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  box-sizing: border-box;
}

.pvam-input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.2);
  border-color: #2563eb;
}

.pvam-input.is-correct {
  border-color: #16a34a;
  background: #f0fdf4;
}

.pvam-input.is-wrong {
  border-color: #dc2626;
  background: #fef2f2;
}

.pvam-static {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
}

.pvam-total-panel {
  display: grid;
  gap: 8px;
}

.pvam-sum-panel {
  display: grid;
  gap: 6px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px;
  background: #f8fafc;
}

.pvam-sum-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}

.pvam-total-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.pvam-total-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
}

.pvam-total-static {
  max-width: 140px;
}

.pvam-submit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.pvam-submit-hint {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.pvam-submit-btn {
  min-width: 88px;
}

@media (max-width: 860px) {
  main {
    padding: 16px;
  }
}

@media (max-width: 600px) {
  header {
    padding: 16px 20px;
  }

  .prompt {
    font-size: 16px;
  }

  .pvam-grid {
    grid-template-columns: 30px repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .pvam-cell {
    min-height: 78px;
    padding: 6px;
  }
}
