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

:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-card: #1c232d;
  --ink: #f0ece2;
  --ink-dim: #8b8578;
  --ink-faint: #4a4538;
  --accent: #F4C430;
  --danger:  #E66F4E;
  --success: #5BA84B;
  --line: rgba(240, 236, 226, 0.08);
  --line-bright: rgba(240, 236, 226, 0.16);
}

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh; min-height: 100dvh;
}
body {
  background-image:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(244, 196, 48, 0.06), transparent 60%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(110, 60, 168, 0.04), transparent 60%);
  background-attachment: fixed;
  overflow-x: hidden;
}
body::before {
  content: ''; position: fixed; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/></svg>");
  pointer-events: none; z-index: 1; mix-blend-mode: overlay;
}

.app {
  position: relative; z-index: 2;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(20px, 5vw, 56px) clamp(16px, 4vw, 40px);
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
}

/* Header */
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: clamp(32px, 5vw, 64px); }
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-mark { width: 14px; height: 14px; background: var(--accent); border-radius: 50%; box-shadow: 0 0 24px var(--accent); align-self: center; }
.brand-name { font-family: 'Fraunces', serif; font-weight: 900; font-size: clamp(20px, 3vw, 26px); letter-spacing: -0.02em; }
.brand-sub { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.18em; display: none; }
@media (min-width: 720px) { .brand-sub { display: inline; } }
.head-meta { font-family: 'Fraunces', serif; font-style: italic; font-size: 13px; color: var(--ink-dim); text-align: right; }
.head-meta span { color: var(--accent); font-style: normal; font-weight: 700; }
.admin-link { color: var(--accent); text-decoration: none; font-weight: 700; font-style: normal; }
.admin-link:hover { text-decoration: underline; }

.view { animation: fadeIn 0.4s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Hero */
.hero { margin-bottom: clamp(20px, 3vw, 32px); max-width: 720px; }
.hero h1 { font-family: 'Fraunces', serif; font-weight: 400; font-size: clamp(36px, 7vw, 68px); line-height: 0.98; letter-spacing: -0.03em; margin-bottom: 16px; }
.hero h1 em { font-style: italic; font-weight: 500; color: var(--accent); }
.hero p { font-size: clamp(15px, 1.6vw, 17px); color: var(--ink-dim); max-width: 540px; line-height: 1.5; }

.overall { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.overall-text { font-size: 14px; color: var(--ink-dim); }
.overall-text strong { color: var(--ink); font-weight: 500; }
.overall-bar { flex: 1; height: 6px; background: rgba(240, 236, 226, 0.06); border-radius: 999px; overflow: hidden; min-width: 120px; }
.overall-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, white)); transition: width 0.5s cubic-bezier(.2,.8,.2,1); }
.reset-all { background: transparent; border: 1px solid var(--line-bright); color: var(--ink-dim); padding: 8px 14px; border-radius: 999px; font: inherit; font-size: 12px; cursor: pointer; transition: all 0.2s; }
.reset-all:hover { border-color: var(--danger); color: var(--danger); }

.mode-bar { margin-bottom: 24px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mode-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.18em; color: var(--ink-dim); margin-right: 6px; }
.chip { background: transparent; border: 1px solid var(--line-bright); color: var(--ink); padding: 8px 16px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer; transition: all 0.2s; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 500; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 14px; }
.cat { position: relative; background: var(--bg-card); border: 1px solid var(--line); border-radius: 14px; padding: 22px 20px 18px; cursor: pointer; text-align: left; color: inherit; font: inherit; transition: transform 0.25s cubic-bezier(.2,.8,.2,1), border-color 0.25s, opacity 0.25s; overflow: hidden; min-height: 144px; display: flex; flex-direction: column; justify-content: space-between; }
.cat::before { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse 80% 50% at 0% 0%, var(--cat-color), transparent 70%); opacity: 0.18; transition: opacity 0.25s; pointer-events: none; }
.cat::after { content: ''; position: absolute; left: 20px; top: 22px; width: 8px; height: 8px; background: var(--cat-color); border-radius: 50%; box-shadow: 0 0 0 4px color-mix(in srgb, var(--cat-color) 20%, transparent); }
.cat:hover, .cat:focus-visible { transform: translateY(-3px); border-color: var(--line-bright); outline: none; }
.cat:hover::before, .cat:focus-visible::before { opacity: 0.35; }
.cat.done { opacity: 0.55; }
.cat.done:hover { opacity: 0.85; }
.cat.flash { animation: flash 1.2s cubic-bezier(.2,.8,.2,1); }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 var(--cat-color); }
  30% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--cat-color) 40%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.cat-num { font-family: 'Fraunces', serif; font-size: 12px; color: var(--ink-dim); letter-spacing: 0.12em; margin-bottom: 8px; padding-left: 20px; }
.cat-name { font-family: 'Fraunces', serif; font-weight: 500; font-size: 22px; line-height: 1.1; letter-spacing: -0.01em; margin-bottom: 14px; }
.cat-progress { margin-top: auto; }
.cat-progress-bar { height: 4px; background: rgba(240, 236, 226, 0.06); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.cat-progress-fill { height: 100%; background: var(--cat-color); transition: width 0.5s cubic-bezier(.2,.8,.2,1); }
.cat-progress-text { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--ink-dim); }
.cat-progress-text .arrow { font-family: 'Fraunces', serif; font-size: 18px; color: var(--cat-color); transition: transform 0.25s; }
.cat:hover .arrow { transform: translateX(4px); }
.cat-progress-text .done-mark { color: var(--cat-color); font-weight: 500; }

/* Quiz */
#quiz-view, #done-view { display: none; flex: 1; flex-direction: column; }
#quiz-view.active, #done-view.active { display: flex; }
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: clamp(28px, 5vw, 48px); padding-bottom: 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.back-btn { background: transparent; border: 1px solid var(--line-bright); color: var(--ink); padding: 10px 16px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer; transition: all 0.2s; }
.back-btn:hover { border-color: var(--accent); color: var(--accent); }
.cat-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; background: color-mix(in srgb, var(--current-color) 14%, transparent); border: 1px solid color-mix(in srgb, var(--current-color) 35%, transparent); font-size: 12px; font-weight: 500; color: var(--current-color); }
.cat-badge .dot { width: 6px; height: 6px; background: var(--current-color); border-radius: 50%; }
.progress-text { font-family: 'Fraunces', serif; font-size: 13px; color: var(--ink-dim); font-style: italic; }
.progress-text strong { color: var(--ink); font-style: normal; font-weight: 700; }
.quiz-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: clamp(20px, 5vw, 60px) 0; max-width: 820px; margin: 0 auto; width: 100%; }
.q-num { font-family: 'Fraunces', serif; font-style: italic; font-size: 14px; color: var(--current-color); letter-spacing: 0.04em; margin-bottom: 24px; opacity: 0; animation: rise 0.5s 0.05s cubic-bezier(.2,.8,.2,1) both; }
.question { font-family: 'Fraunces', serif; font-weight: 400; font-size: clamp(26px, 4.4vw, 44px); line-height: 1.18; letter-spacing: -0.02em; margin-bottom: clamp(36px, 6vw, 56px); opacity: 0; animation: rise 0.6s 0.1s cubic-bezier(.2,.8,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
.reveal-btn, .done-btn { background: var(--current-color); color: var(--bg); border: none; font: inherit; font-weight: 500; font-size: 15px; padding: 16px 36px; border-radius: 999px; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 8px 24px color-mix(in srgb, var(--current-color) 35%, transparent); }
.reveal-btn { opacity: 0; animation: rise 0.6s 0.2s cubic-bezier(.2,.8,.2,1) both; }
.reveal-btn:hover, .done-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 32px color-mix(in srgb, var(--current-color) 45%, transparent); }
.done-btn { display: inline-flex; align-items: center; gap: 10px; }
.done-btn .check { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; background: var(--bg); color: var(--current-color); border-radius: 50%; font-size: 13px; font-weight: 700; }
.answer-wrap { width: 100%; margin-top: clamp(36px, 6vw, 56px); opacity: 0; max-height: 0; overflow: hidden; transition: opacity 0.5s ease, max-height 0.6s cubic-bezier(.2,.8,.2,1); }
.answer-wrap.show { opacity: 1; max-height: 800px; }
.answer-label { font-family: 'Fraunces', serif; font-style: italic; font-size: 13px; text-transform: lowercase; color: var(--ink-dim); letter-spacing: 0.08em; margin-bottom: 14px; display: flex; align-items: center; justify-content: center; gap: 14px; }
.answer-label::before, .answer-label::after { content: ''; flex: 1; height: 1px; background: var(--line); max-width: 80px; }
.answer { font-family: 'Fraunces', serif; font-style: italic; font-weight: 500; font-size: clamp(22px, 3.4vw, 32px); line-height: 1.3; letter-spacing: -0.015em; color: var(--current-color); margin-bottom: 36px; }

.kbd-hint { margin-top: 18px; font-size: 11px; color: var(--ink-faint); text-align: center; letter-spacing: 0.06em; text-transform: uppercase; }
.kbd { display: inline-block; padding: 2px 8px; border: 1px solid var(--line-bright); border-radius: 4px; font-family: monospace; font-size: 10px; color: var(--ink-dim); margin: 0 2px; }

/* Done */
.done-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: clamp(40px, 8vw, 80px) 0; max-width: 600px; margin: 0 auto; width: 100%; }
.done-mark { width: 80px; height: 80px; border-radius: 50%; background: color-mix(in srgb, var(--current-color) 18%, transparent); border: 2px solid var(--current-color); display: flex; align-items: center; justify-content: center; margin-bottom: 32px; font-family: 'Fraunces', serif; font-size: 36px; color: var(--current-color); animation: pop 0.6s cubic-bezier(.2,.8,.2,1) both; }
@keyframes pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}
.done-title { font-family: 'Fraunces', serif; font-size: clamp(32px, 5vw, 48px); line-height: 1.05; letter-spacing: -0.02em; margin-bottom: 16px; font-weight: 400; }
.done-title em { font-style: italic; color: var(--current-color); font-weight: 500; }
.done-sub { font-size: 16px; color: var(--ink-dim); margin-bottom: 44px; }
.done-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

.btn-primary, .btn-secondary { font: inherit; font-size: 14px; padding: 14px 24px; border-radius: 999px; cursor: pointer; transition: all 0.2s; border: none; }
.btn-primary { background: var(--current-color, var(--accent)); color: var(--bg); font-weight: 500; box-shadow: 0 8px 24px color-mix(in srgb, var(--current-color, var(--accent)) 30%, transparent); }
.btn-primary:hover { transform: translateY(-2px); }
.btn-secondary { background: transparent; color: var(--ink); border: 1px solid var(--line-bright); }
.btn-secondary:hover { border-color: var(--current-color, var(--accent)); color: var(--current-color, var(--accent)); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; animation: fadeIn 0.25s ease both; }
.modal-bg.show { display: flex; }
.modal { background: var(--bg-elev); border: 1px solid var(--line-bright); border-radius: 16px; padding: 28px; max-width: 380px; width: 100%; text-align: center; }
.modal h3 { font-family: 'Fraunces', serif; font-size: 22px; margin-bottom: 12px; font-weight: 500; }
.modal p { color: var(--ink-dim); font-size: 14px; line-height: 1.5; margin-bottom: 22px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.btn-danger { background: var(--danger); color: var(--bg); border: none; padding: 10px 20px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.btn-danger:hover { opacity: 0.9; }
.btn-cancel { background: transparent; color: var(--ink); border: 1px solid var(--line-bright); padding: 10px 20px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer; }

footer { margin-top: auto; padding-top: 48px; text-align: center; font-size: 12px; color: var(--ink-faint); letter-spacing: 0.1em; text-transform: uppercase; }

/* Loading / Empty states */
.empty { text-align: center; padding: 80px 20px; color: var(--ink-dim); }
.empty h2 { font-family: 'Fraunces', serif; font-size: 28px; color: var(--ink); margin-bottom: 12px; font-weight: 500; }

/* ============== ADMIN ============== */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.admin-tab { background: none; border: none; color: var(--ink-dim); padding: 10px 18px; font: inherit; font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; margin-bottom: -1px; }
.admin-tab:hover { color: var(--ink); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.admin-toolbar input[type="search"] { flex: 1; min-width: 180px; background: var(--bg-card); border: 1px solid var(--line-bright); border-radius: 8px; padding: 9px 14px; font: inherit; font-size: 14px; color: var(--ink); }
.admin-toolbar input[type="search"]::placeholder { color: var(--ink-faint); }
.admin-toolbar input[type="search"]:focus { outline: none; border-color: var(--accent); }

.btn { background: var(--bg-card); color: var(--ink); border: 1px solid var(--line-bright); padding: 9px 16px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; transition: all 0.2s; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.btn-accent { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 500; }
.btn.btn-accent:hover { opacity: 0.9; color: var(--bg); }
.btn.btn-icon { padding: 8px 10px; min-width: 36px; }
.btn.btn-small { padding: 6px 10px; font-size: 12px; }

.admin-table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: 12px; overflow: hidden; }
.admin-table thead { background: var(--bg-elev); }
.admin-table th { text-align: left; padding: 12px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); font-weight: 500; border-bottom: 1px solid var(--line); }
.admin-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(240, 236, 226, 0.02); }
.admin-table .color-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.admin-table .actions { white-space: nowrap; text-align: right; }
.admin-table .actions .btn { margin-left: 4px; }
.admin-table .q-cell { max-width: 400px; }
.admin-table .a-cell { color: var(--ink-dim); font-style: italic; max-width: 300px; }
.admin-table .count-cell { color: var(--ink-dim); font-variant-numeric: tabular-nums; }

.modal.modal-lg { max-width: 580px; text-align: left; }
.modal.modal-lg h3 { text-align: center; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); margin-bottom: 6px; }
.field input, .field textarea, .field select { width: 100%; background: var(--bg); border: 1px solid var(--line-bright); border-radius: 8px; padding: 10px 14px; font: inherit; font-size: 14px; color: var(--ink); resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 120px; gap: 12px; }
.color-input-wrap { display: flex; gap: 8px; align-items: center; }
.color-input-wrap input[type="color"] { width: 44px; height: 38px; padding: 2px; cursor: pointer; }

.admin-empty { text-align: center; padding: 48px 16px; color: var(--ink-dim); font-size: 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--bg-elev); border: 1px solid var(--line-bright); border-radius: 8px; padding: 10px 18px; font-size: 13px; opacity: 0; pointer-events: none; transition: all 0.25s; z-index: 200; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cat { min-height: 132px; padding: 18px 16px 16px; }
  .cat-name { font-size: 17px; }
  .cat::after { left: 16px; top: 18px; }
  .cat-num { padding-left: 16px; }
  .quiz-head { flex-wrap: wrap; gap: 10px; }
  .admin-table th, .admin-table td { padding: 10px 8px; font-size: 13px; }
  .admin-table .q-cell { max-width: 200px; }
  .field-row { grid-template-columns: 1fr; }
}
