:root {
  --bg: #f3f5f9;
  --side: #ffffff;
  --panel: #ffffff;
  --line: #e2e6ee;
  --text: #1c2333;
  --muted: #7a8396;
  --soft: #f6f8fb;
  --accent: #1d7a4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3ea;
  --ok: #15924a;
  --ok-soft: #e7f6ed;
  --bad: #d83a3f;
  --bad-soft: #fdecec;
  --warn: #b36b00;
  --ask: #e8590c;
  --tabbar: #eef1f6;
  --tab-hover: #e2e7ef;
  --dot: #b7bfcd;
  --hint-bg: #fff7e6;
  --hint-fg: #8a5a00;
  --ch-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 6px rgba(15, 23, 42, .06);
  --ch-shadow-hover: 0 3px 10px rgba(15, 23, 42, .12);
  /* Sheet */
  --xg-line: #e1e4ea;
  --xg-head: #f1f3f6;
  --xg-head-ink: #5d6677;
  --xg-head-on: #d5ebdf;
  --xg-head-on-ink: #145c3a;
  --xg-cellhead: #edf5f0;
  --xg-tb: #8d96a6;
  --xg-ans: #fff6cc;
  --xg-sel: rgba(29, 122, 79, .12);
  --xg-act: #1d7a4f;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --mono: 'JetBrains Mono', D2Coding, Consolas, monospace;
  --exam: #f2621b;
  --shadow: rgba(0, 0, 0, .25);
  --spring: cubic-bezier(.34, 1.45, .64, 1); /* overshoots slightly and settles back */
  /* Chapter hover mark: a green tile with an X (cut out) and a sheet behind it, drawn as two layers that slide together */
  --xl-tile: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cmask id='m'%3E%3Crect width='40' height='40' fill='white'/%3E%3Cpath d='M9.5 14.5l11 11M20.5 14.5l-11 11' stroke='black' stroke-width='3.6' stroke-linecap='round'/%3E%3C/mask%3E%3Crect x='2' y='7' width='26' height='26' rx='5' fill='%23107c41' mask='url(%23m)'/%3E%3C/svg%3E");
  --xl-sheet: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect x='15' y='4' width='22' height='32' rx='3' fill='%23dff2e7' stroke='%2321a366' stroke-width='1.6'/%3E%3Cpath d='M15 12h22M15 20h22M15 28h22M26 4v32' stroke='%2321a366' stroke-width='1.3'/%3E%3C/svg%3E");
  --xl-op: .3;
  --xl-op-active: .22;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a0d12;
  --side: #151a23;
  --panel: #1a202b;
  --line: #374154;
  --text: #eef1f6;
  --muted: #a6afc0;
  --soft: #232a37;
  --accent: #3dbb7c;
  --accent-ink: #08130d;
  --accent-soft: #15301f;
  --ok: #34c473;
  --ok-soft: #13301f;
  --bad: #ff6b70;
  --bad-soft: #3a1b1e;
  --warn: #f0b04a;
  --ask: #ff8a47;
  --tabbar: #11151c;
  --tab-hover: #222a37;
  --dot: #5c677c;
  --hint-bg: #33290f;
  --hint-fg: #f0c869;
  --ch-shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 6px rgba(0, 0, 0, .25);
  --ch-shadow-hover: 0 4px 12px rgba(0, 0, 0, .45);
  --xg-line: #2f3848;
  --xg-head: #202734;
  --xg-head-ink: #9aa4b6;
  --xg-head-on: #1d3a2b;
  --xg-head-on-ink: #8de0b2;
  --xg-cellhead: #1c2a23;
  --xg-tb: #6c7689;
  --xg-ans: #3a3317;
  --xg-sel: rgba(61, 187, 124, .16);
  --xg-act: #3dbb7c;
  --exam: #ff7a33;
  --shadow: rgba(0, 0, 0, .6);
  --xl-op: .5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Pretendard, -apple-system, 'Malgun Gothic', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  font-variant-ligatures: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.btn, .icon-btn, .tab, .chapter, .side-intro, .step .dot, .nav-btn {
  transition: background-color .18s, color .18s, border-color .18s, transform .18s var(--ease), box-shadow .18s, opacity .18s;
}
.btn:active:not(:disabled), .icon-btn:active { transform: scale(.96); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
.enter { animation: fadeUp .28s var(--ease); }
.theme-anim, .theme-anim * { transition: background-color .35s, color .35s, border-color .35s !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ===== Buttons ===== */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--soft); color: var(--text); }

/* ===== Layout ===== */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: 220px;
  flex: none;
  background: var(--side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: margin-left .22s var(--ease);
}
body.side-collapsed #sidebar { margin-left: -220px; }
#sideOpen { position: fixed; left: 8px; top: 18px; z-index: 5; opacity: 0; pointer-events: none; transition: opacity .2s; }
body.side-collapsed #sideOpen { opacity: 1; pointer-events: auto; }
body.side-collapsed #topbar { padding-left: 52px; }
.side-head { display: flex; align-items: center; gap: 4px; padding: 18px 10px 14px 16px; }
.logo { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.logo-mark { width: 30px; height: 30px; flex: none; }
.logo-text { font-weight: 800; font-size: 16px; line-height: 1.1; display: flex; flex-direction: column; }
.logo-text small { font-weight: 500; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
#themeToggle .i-sun { display: none; }
:root[data-theme="dark"] #themeToggle .i-sun { display: block; }
:root[data-theme="dark"] #themeToggle .i-moon { display: none; }

#chapterList { flex: 1; overflow-y: auto; padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 5px; }
.chapter {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: var(--panel);
  box-shadow: var(--ch-shadow);
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}
.chapter:hover { box-shadow: var(--ch-shadow-hover); transform: translateX(5px); }
.chapter.active {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 78%, #000));
  color: #fff;
  box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 40%, transparent);
}
/* Chapter hover: the X tile comes from the upper left and the sheet from the lower right, meeting as one mark (like pyjudge's Python logo).
   Both are background layers of a single ::after so the overlap does not get brighter */
.chapter { position: relative; overflow: hidden; isolation: isolate; }
.chapter > * { position: relative; z-index: 1; }
.chapter::after {
  content: ''; position: absolute; z-index: 0; pointer-events: none;
  right: -30px; top: 50%; width: 120px; height: 120px; margin-top: -60px;
  background-image: var(--xl-tile), var(--xl-sheet);
  background-repeat: no-repeat; background-size: 42px 42px;
  background-position: calc(50% - 12px) calc(50% - 28px), calc(50% + 12px) calc(50% + 28px);
  opacity: 0; rotate: -40deg;
  transition: background-position .6s var(--spring), rotate .6s var(--spring), opacity .3s;
}
.chapter:hover::after { opacity: var(--xl-op); background-position: 50% 50%, 50% 50%; rotate: -12deg; }
/* Chapter being viewed: a faint white mark that opens slightly and closes again on hover */
.chapter.active::after {
  filter: brightness(0) invert(1);
  opacity: calc(var(--xl-op-active) * .7); background-position: 50% 50%, 50% 50%; rotate: -12deg;
}
.chapter.active:hover::after { opacity: var(--xl-op-active); animation: xlBreathe .8s; }
@keyframes xlBreathe {
  0% { animation-timing-function: cubic-bezier(.3, 0, .2, 1); }
  40% {
    background-position: calc(50% - 3px) calc(50% - 6px), calc(50% + 3px) calc(50% + 6px); rotate: -24deg;
    animation-timing-function: cubic-bezier(.45, 0, .25, 1.3);
  }
}
.ch-name { flex: 1; min-width: 0; font-weight: 600; }
.part-label { margin: 12px 4px 2px; font-size: 12.5px; font-weight: 700; color: var(--text); display: flex; align-items: baseline; gap: 6px; }
.part-label small { font-weight: 500; color: var(--muted); font-size: 11px; }
.later { font-size: 12px; color: var(--muted); padding: 2px 6px; }
/* ===== Below the left menu: exam site, sister site (same as pyjudge) ===== */
.side-foot { margin-top: auto; padding: 10px 12px 14px; }
.site-row { position: relative; display: flex; gap: 6px; margin: 0 2px; }
.sis { position: static; }
.pill-btn {
  display: flex; align-items: center; gap: 3px; height: 26px; padding: 0 8px 0 10px;
  font: inherit; font-size: 11px; font-weight: 500; letter-spacing: -.01em; color: var(--muted);
  background: color-mix(in srgb, var(--accent) 12%, transparent); border: 0; border-radius: 999px; cursor: pointer;
  transition: background-color .25s, color .25s, box-shadow .25s;
}
.pill-btn svg { width: 10px; height: 10px; transition: transform .25s; }
.pill-btn:hover { color: var(--text); }
.pill-btn[aria-expanded="true"] { background: var(--panel); color: var(--accent); box-shadow: 0 2px 8px -4px rgba(0, 0, 0, .25); }
.pill-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.pill-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sis-pop {
  position: absolute; left: calc(100% + 24px); bottom: -4px; z-index: 30;
  width: 272px; padding: 8px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 18px 40px -16px var(--shadow);
  transform-origin: 0 100%; animation: sisIn .22s var(--ease) both;
}
.sis-pop::before {
  content: ''; position: absolute; left: -6px; bottom: 16px; width: 10px; height: 10px;
  background: var(--panel); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg);
}
@keyframes sisIn { from { opacity: 0; transform: translateX(-6px) scale(.97); } }
.sis-hd { padding: 4px 10px 6px; font-size: 11px; font-weight: 600; color: var(--muted); }
.sis-ft { margin: 6px 4px 0; padding: 8px 6px 2px; border-top: 1px dashed var(--line); font-size: 11px; color: var(--muted); }
.sis-item {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; color: inherit; text-decoration: none;
  transition: background-color .18s;
}
.sis-item:hover { background: var(--soft); }
.sis-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.sis-key { width: 34px; height: 34px; }
.sis-icon { width: 34px; height: 34px; display: grid; place-items: center; color: var(--accent); }
.sis-text b { display: block; font-size: 14px; font-weight: 700; line-height: 1.2; }
.sis-text small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
.ref-go { flex: none; margin-left: auto; opacity: .5; transition: opacity .18s, transform .18s var(--ease); }
.sis-item:hover .ref-go { opacity: 1; transform: translate(1px, -1px); }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px 10px;
  transition: padding-left .22s var(--ease);
}
#chapterTitle { font-size: 20px; margin: 0; white-space: nowrap; }
#steps { list-style: none; margin: 0 0 0 auto; padding: 0; display: flex; gap: 6px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; min-width: 74px; position: relative; }
.step + .step::before {
  content: '';
  position: absolute;
  top: 14px;
  right: calc(50% + 16px);
  width: calc(100% - 26px);
  height: 2px;
  background: var(--line);
}
.step .dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--dot);
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  position: relative;
}
.step .label { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.step:hover .dot { border-color: var(--accent); color: var(--accent); }
.step.active .dot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); transform: scale(1.08); }
.step.active .label { color: var(--text); font-weight: 600; }

#workspace { flex: 1; min-height: 0; display: flex; gap: 14px; padding: 0 16px 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#left { flex: 2; min-width: 320px; }
#right { flex: 3; min-width: 420px; }

/* ===== Left panel ===== */
.tabbar { display: flex; align-items: center; gap: 10px; padding: 8px 10px 0; background: var(--tabbar); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; align-self: flex-end; }
.tab {
  border: 1px solid transparent;
  border-bottom: 0;
  background: transparent;
  padding: 7px 16px 8px;
  border-radius: 9px 9px 0 0;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: -1px;
}
.tab:hover { background: var(--tab-hover); }
.tab.active { background: var(--panel); border-color: var(--line); color: var(--text); }
.tabs.instant .tab { transition: none; }
#typeTitle { font-size: 14.5px; margin: 0 0 6px; flex: 1; min-width: 0; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-nav { display: flex; gap: 4px; flex-shrink: 0; margin-bottom: 6px; }
.nav-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 3px 9px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.nav-btn:hover:not(:disabled) { color: var(--text); background: var(--soft); }
.nav-btn:disabled { opacity: .4; cursor: default; }
#leftBody { flex: 1; min-height: 0; overflow-y: auto; }
#lecturePane { padding: 22px; display: flex; flex-direction: column; align-items: center; gap: 28px; }
#video { width: 100%; aspect-ratio: 16 / 9; }
#video iframe { width: 100%; height: 100%; border: 0; border-radius: 10px; }
.no-video {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  background: var(--soft);
  border: 1px dashed var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
  word-break: keep-all;
}
.sorry-face { width: 64px; height: 64px; }
.go-problem { width: 60%; max-width: 420px; padding: 13px 18px; font-size: 16px; border-radius: 10px; }
.go-arrow { display: inline-block; transition: transform .2s var(--ease); }
.go-problem:hover .go-arrow { transform: translateX(4px); }

#problemPane { padding: 16px 18px 22px; }
.problem-tools { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tools-right { display: flex; gap: 6px; }
.problem-tag { font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 3px 9px; border-radius: 99px; }
.explain { margin-top: 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); }
.explain summary { cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: 14px; color: var(--muted); list-style: none; }
.explain summary::before { content: '▸ '; display: inline-block; transition: transform .2s; }
.explain[open] summary::before { transform: rotate(90deg); }
.explain summary:hover { color: var(--text); }
.explain .prose { padding: 0 14px 12px; animation: fadeIn .2s; }

/* ===== Right panel ===== */
.right-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 46px; }
.right-title { font-weight: 700; font-size: 14px; }
.right-head .keys { font-size: 12px; color: var(--muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#notesView { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#notesBody { flex: 1; overflow-y: auto; padding: 6px 24px 30px; }
#workView { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#gridHost { flex: 1; min-height: 0; display: flex; padding: 12px 14px 0; }
#checkBar { display: flex; align-items: center; gap: 12px; padding: 12px 14px; justify-content: flex-end; }
#answerBox { display: flex; align-items: center; gap: 8px; flex: 1; }
#answerBox label { font-weight: 700; }
#answerInput {
  flex: 1;
  max-width: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: var(--panel);
  color: var(--text);
}
#answerInput.mono { font-family: var(--mono); font-size: 14px; }
#answerInput:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#selInfo { flex: 1; color: var(--muted); font-size: 14px; }
#selInfo b { font-family: var(--mono); color: var(--text); margin-left: 6px; }
#checkBtn { padding: 9px 22px; }
#result { padding: 0 14px; }
#result:empty { display: none; }
#result.ok, #result.bad { margin: 0 14px 14px; padding: 12px 14px; border-radius: 10px; }
#result.ok { background: var(--ok-soft); }
#result.bad { background: var(--bad-soft); }
#result.pop { animation: pop .25s var(--ease); }
.res { display: flex; gap: 12px; align-items: flex-start; }
.res-ico { width: 26px; height: 26px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; }
#result.ok .res-ico { background: var(--ok); }
#result.bad .res-ico { background: var(--bad); }
.res-body p { margin: 4px 0 0; line-height: 1.55; word-break: keep-all; }
.res-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ===== Intro ===== */
#introView { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 24px; }
.intro { max-width: 820px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 36px 30px; }
.intro h2 { font-size: 24px; margin: 22px 0 6px; }
.intro .lead { color: var(--muted); font-size: 16px; }
.intro-go { text-align: center; margin-top: 28px; }

/* ===== Prose (notes, problems) ===== */
.prose { line-height: 1.75; word-break: keep-all; }
.prose h3 {
  font-size: 16.5px;
  margin: 26px 0 8px;
  padding-left: 11px;
  border-left: 4px solid var(--accent);
  color: var(--accent);
}
.prose p { margin: 8px 0; }
.prose ul, .prose ol { margin: 6px 0; padding-left: 22px; }
.prose li { margin: 3px 0; }
.prose b { color: var(--hint-fg); background: linear-gradient(transparent 58%, var(--hint-bg) 58%); }
.prose code, .prose b.addr {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 5px;
  color: var(--text);
  white-space: nowrap;
}
.prose b.addr { color: var(--accent); font-weight: 700; }
.prose table.t { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.prose table.t th, .prose table.t td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; vertical-align: top; }
.prose table.t th { background: var(--soft); font-weight: 700; }
.prose .ex {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 13px;
  font-size: 14.5px;
}
.prose .tip {
  margin: 18px 0 8px;
  background: var(--hint-bg);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}
.prose .tip > b.tip-title { background: none; display: block; margin-bottom: 2px; }
.prose .tip ul { margin: 2px 0; }
.prose .hint { color: var(--muted); font-size: 13.5px; }
.prose .q {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  background: var(--soft);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.75;
  margin-bottom: 10px;
}
.prose .q .arrow { margin-top: 6px; padding-left: 10px; color: var(--text); font-size: 14.5px; }
.prose .q .qno {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin-right: 4px;
  border-radius: 50%; background: var(--accent); color: #fff; font-size: 12.5px; vertical-align: 1px;
}
.fig { margin: 14px 0 18px; padding-top: 6px; }

/* ===== Toasts ===== */
#toasts { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast {
  background: #1f2633;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  animation: toastIn .25s var(--ease);
  transition: opacity .3s, transform .3s;
  max-width: 560px;
  text-align: center;
  word-break: keep-all;
}
.toast.warn { background: #6b4300; }
.toast.bad { background: #8c1d22; }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ===== Sheet grid ===== */
.xg { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.xg-static { flex: none; display: inline-flex; max-width: 100%; border-radius: 6px; }
.xg-bar { display: flex; align-items: center; gap: 6px; padding: 5px 6px; background: var(--soft); border-bottom: 1px solid var(--line); }
.xg-name, .xg-formula {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 7px;
  font-family: var(--mono);
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
  height: 27px;
}
.xg-name { width: 92px; text-align: center; }
.xg-formula { flex: 1; min-width: 60px; }
.xg-name:focus, .xg-formula:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.xg-fx { color: var(--muted); font-style: italic; font-family: Georgia, serif; padding: 0 4px; user-select: none; }
.xg-scroll { flex: 1; min-height: 0; overflow: auto; }
.xg-static .xg-scroll { overflow: visible; }
.xg-sheet { position: relative; display: inline-block; vertical-align: top; }
.xg-table { border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.xg-table th {
  background: var(--xg-head);
  color: var(--xg-head-ink);
  font-weight: 500;
  font-size: 12px;
  height: 24px;
  border: 1px solid var(--xg-line);
  text-align: center;
  user-select: none;
  transition: background-color .12s, color .12s;
}
.xg-table th.on { background: var(--xg-head-on); color: var(--xg-head-on-ink); font-weight: 700; }
.xg-table td {
  height: 26px;
  padding: 0 5px;
  border: 1px solid var(--xg-line);
  white-space: nowrap;
  overflow: hidden;
  cursor: cell;
  user-select: none;
  line-height: 24px;
}
.xg-static .xg-table td { cursor: default; }
.xg-table td.t-n { text-align: right; }
.xg-table td.t-c { text-align: center; }
.xg-table td.t-err { color: var(--bad); }
.xg-table td.t-f { font-family: var(--mono); font-size: 12.5px; color: var(--accent); }
.xg-table td.head { background: var(--xg-cellhead); font-weight: 700; text-align: center; }
.xg-table td.title { font-weight: 700; overflow: visible; }
.xg-table td.answer { background: var(--xg-ans); }
.xg-table td.tb { border-color: var(--xg-tb); }
.xg-layer { position: absolute; inset: 0; pointer-events: none; }
.xg-layer > div, .xg-mark, .xg-ref { position: absolute; }
.xg-sel { background: var(--xg-sel); }
.xg-act { border: 2px solid var(--xg-act); transition: left .06s, top .06s, width .06s, height .06s; }
.xg-handle { width: 8px; height: 8px; background: var(--xg-act); border: 1.5px solid var(--panel); pointer-events: auto; cursor: crosshair; z-index: 3; }
.xg.filling, .xg.filling * { cursor: crosshair !important; }
.xg-fillprev { border: 2px dashed var(--muted); }
.xg-ants { border: 2px dashed var(--accent); animation: ants 1s linear infinite alternate; }
@keyframes ants { from { opacity: 1; } to { opacity: .35; } }
.xg-ref { border: 2px solid var(--rc); background: color-mix(in srgb, var(--rc) 10%, transparent); }
.xg-mark { border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 2px; animation: fadeIn .2s; }
.xg-mark.tone-ask { border-color: var(--ask); background: color-mix(in srgb, var(--ask) 12%, transparent); }
.xg-mark.tone-fill { border: 2px dashed #3b82f6; background: transparent; }
.xg-mark.tone-bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.xg-mark.tone-want { border: 2px dashed var(--ok); background: transparent; }
.xg-mark-label {
  position: absolute;
  left: -2px;
  bottom: 100%;
  margin-bottom: 1px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 4px 4px 4px 0;
  background: var(--accent);
  color: var(--accent-ink);
  white-space: nowrap;
  font-family: var(--mono);
}
.xg-mark-label.at-right { left: 100%; bottom: auto; top: 50%; transform: translateY(-50%); margin: 0 0 0 5px; border-radius: 4px; }
.xg-mark-label.at-below { bottom: auto; top: 100%; margin: 2px 0 0; border-radius: 0 4px 4px 4px; }
.tone-ask .xg-mark-label { background: var(--ask); color: #fff; }
.tone-fill .xg-mark-label { background: #3b82f6; color: #fff; }
.xg-editor {
  position: absolute;
  z-index: 5;
  margin: 0;
  border: 2px solid var(--xg-act);
  padding: 0 4px;
  font: inherit;
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  opacity: 0;
  pointer-events: none;
}
.xg.editing .xg-editor { opacity: 1; pointer-events: auto; box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.xg.editing .xg-act { opacity: 0; }

/* ===== Step dot for the 실전평가 ===== */
.step.exam .dot { border-color: color-mix(in srgb, var(--exam) 55%, var(--dot)); color: var(--exam); display: inline-flex; align-items: center; justify-content: center; }
.step.exam:hover .dot { border-color: var(--exam); color: var(--exam); }
.step.exam.active .dot { background: var(--exam); border-color: var(--exam); color: #fff; }

/* ===== 실전평가 page (left) and info (right) ===== */
#examView { padding: 22px 24px; animation: fadeIn .25s var(--ease); }
.ex-tag {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 11px; border-radius: 999px;
  background: color-mix(in srgb, var(--exam) 15%, transparent); color: var(--exam);
}
.ex-title { margin: 10px 0 0; font-size: 19px; }
.ex-info { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; margin: 16px 0 18px; font-size: 14px; }
.ex-info dt { color: var(--muted); }
.ex-info dd { margin: 0; font-weight: 600; }
.rules { padding-left: 20px; line-height: 1.9; margin: 0 0 22px; font-size: 14px; }
.rules b { color: var(--exam); }
.btn.exam { background: var(--exam); border-color: var(--exam); color: #fff; }
.btn.exam:hover:not(:disabled) { filter: brightness(1.08); }
.btn.exam.go-problem { display: block; margin: 0 auto; box-shadow: 0 4px 14px color-mix(in srgb, var(--exam) 32%, transparent); }
.ex-covers { margin: 0; padding-left: 18px; font-weight: 500; line-height: 1.7; }
.ex-tips { margin: -6px 0 22px; }
.ex-tips .tip { margin: 0; }

/* ===== 도전자 명단 (same look as pyjudge): content-width chips, as many per row as fit ===== */
#fameView { display: flex; flex-direction: column; flex: 1; min-height: 0; animation: fadeIn .25s var(--ease); }
#fameView[hidden] { display: none; }
#fameBody { flex: 1; min-height: 0; overflow: auto; padding: 12px 16px 18px; }
.fame-count { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.fame-sort { margin-left: auto; display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); }
.fame-sort button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 5px; cursor: pointer; transition: background .2s, color .2s, box-shadow .2s;
}
.fame-sort button:hover { color: var(--text); }
.fame-sort button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.fame-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 5px; }
.fame-list li { display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 8px; border-radius: 6px; background: var(--soft); animation: fadeIn .3s var(--ease); }
.fame-nick { font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.fame-date { font-size: 10px; color: var(--muted); white-space: nowrap; }
.fame-list li.me { background: color-mix(in srgb, var(--exam) 20%, transparent); animation: fameIn .6s var(--ease); }
@keyframes fameIn { from { opacity: .2; transform: scale(.94); } }
.fame-empty { padding: 60px 0; text-align: center; line-height: 1.8; color: var(--muted); }

/* ===== Exam mode: everything but the problem and the sheet is hidden, orange frame visible from afar ===== */
#examBadge { display: none; align-items: center; gap: 12px; margin-left: auto; font-weight: 800; }
#examBadge .exam-label { font-size: 15px; }
#timer { font-family: var(--mono); font-size: 26px; font-variant-numeric: tabular-nums; background: rgba(255, 255, 255, .18); padding: 2px 12px; border-radius: 9px; }
#examBadge.hurry #timer { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .55; } }
body.exam #sidebar, body.exam #sideOpen, body.exam #steps, body.exam .step-nav,
body.exam #newProblem, body.exam #explain, body.exam .right-head .keys { display: none !important; }
body.exam #topbar { padding: 14px 40px; background: var(--exam); color: #fff; }
body.exam #examBadge { display: flex; }
body.exam #workspace { padding-top: 16px; }
body.exam #typeTitle { margin-bottom: 8px; }
body.exam::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 40;
  border: 10px solid var(--exam);
  animation: examPulse 2.4s ease-in-out infinite;
}
@keyframes examPulse { 50% { border-color: #ff9a5c; } }

/* ===== Modals (out, pass, confirm) ===== */
#modalLayer {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(17, 21, 31, .55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
#modalLayer:not([hidden]) { animation: fadeIn .2s ease; }
.modal:not([hidden]) { animation: pop .28s var(--ease); }
.modal {
  background: var(--panel); border-radius: 18px; padding: 30px 34px;
  width: min(560px, 100%); max-height: calc(100vh - 48px); overflow: auto; box-shadow: 0 20px 60px var(--shadow);
}
.modal .sub { color: var(--muted); margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal .big { font-size: 44px; font-weight: 900; letter-spacing: -.02em; }
.modal.out { text-align: center; border-top: 10px solid var(--bad); }
.modal.out .big { color: var(--bad); }
.modal.out #outReason { font-size: 17px; font-weight: 600; }
.modal.out .modal-actions { justify-content: center; }
.modal.pass { width: min(1100px, 100%); border: 6px solid var(--ok); }
.modal.pass .big { color: var(--ok); }
.modal.nick { width: min(470px, 100%); border-top: 10px solid var(--ok); }
.modal.nick .big { font-size: 25px; }
.nick-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.nick-row { display: flex; gap: 8px; }
.nick-row input {
  flex: 1; min-width: 0; height: 44px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--soft); border: 1px solid var(--line); border-radius: 10px; outline: none; transition: border-color .15s;
}
.nick-row input:focus { border-color: var(--exam); }
.nick-msg { min-height: 20px; margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.nick-msg.err { color: var(--bad); }
.reg-warn { margin: 6px 0 0; font-size: 12px; color: var(--muted); opacity: .8; }
.pass-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.clock-box { text-align: right; }
.clock-label { font-size: 13px; color: var(--muted); font-weight: 700; }
#liveClock { font-family: var(--mono); font-size: 46px; font-weight: 600; font-variant-numeric: tabular-nums; }
.live-bar { height: 6px; border-radius: 3px; background: var(--ok-soft); overflow: hidden; }
.live-bar span { display: block; height: 100%; width: 30%; background: var(--ok); border-radius: 3px; animation: slide 1.6s linear infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.pass-info { display: grid; grid-template-columns: auto 1fr; gap: 4px 18px; margin: 14px 0 18px; font-size: 16px; }
.pass-info dt { color: var(--muted); font-weight: 700; }
.pass-info dd { margin: 0; font-weight: 700; }
.pass-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.col-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.pass-box { max-height: 42vh; overflow: auto; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; font-size: 14.5px; }
.pass-box .q { background: var(--panel); }
.work-task + .work-task { margin-top: 12px; }
.work-head { font-weight: 700; margin-bottom: 4px; }
.work-line { display: flex; gap: 14px; font-family: var(--mono); font-size: 15px; line-height: 1.7; }
.work-line span { color: var(--muted); min-width: 34px; }
.work-line code { font-family: var(--mono); }
.modal.warn { width: min(420px, 100%); text-align: center; }
.warn-ico {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center;
  color: var(--exam); background: color-mix(in srgb, var(--exam) 14%, transparent);
  animation: warnPop .4s var(--spring), warnWiggle .5s .45s ease-in-out;
}
@keyframes warnPop { from { transform: scale(.5); opacity: 0; } }
@keyframes warnWiggle { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }
.warn-q { font-size: 22px; font-weight: 800; line-height: 1.35; margin: 6px 0 10px; }
.modal.warn .modal-actions { justify-content: center; }
