:root {
  --ink: #162036;
  --muted: #68738a;
  --line: #dfe5ef;
  --paper: #ffffff;
  --canvas: #f4f7fb;
  --primary: #3056d3;
  --primary-dark: #203fa8;
  --accent: #13a87b;
  --danger: #d53f4f;
  --warning: #d98b13;
  --shadow: 0 18px 48px rgba(30, 45, 80, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.65;
}
a { color: inherit; text-decoration: none; }
button, select, input, textarea { font: inherit; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid rgba(223,229,239,.9);
  background: rgba(255,255,255,.92); backdrop-filter: blur(14px);
}
.nav { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; color: white; background: linear-gradient(135deg, var(--primary), #7049e8); }
.nav-links { display: flex; align-items: center; gap: 22px; color: #465169; font-weight: 600; }
.nav-links a:hover, .nav-links a.active { color: var(--primary); }

.hero { padding: 64px 0 34px; display: grid; grid-template-columns: 1.4fr .6fr; gap: 34px; align-items: center; }
.eyebrow { color: var(--primary); font-size: 13px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 10px 0 14px; max-width: 760px; font-size: clamp(34px, 5vw, 58px); line-height: 1.08; letter-spacing: -.04em; }
.lead { max-width: 720px; color: var(--muted); font-size: 18px; }
.hero-card, .panel, .problem-card { background: var(--paper); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.hero-card { padding: 24px; }
.stat { display: flex; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); }
.stat:last-child { border: 0; }
.stat strong { color: var(--primary); }

.section { padding: 24px 0 42px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.section-head h2, .panel h2 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.section-head p { margin: 4px 0 0; color: var(--muted); }
.books { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
.book {
  position: relative; min-height: 154px; padding: 20px 16px; overflow: hidden;
  border: 1px solid #cad4ef; border-radius: 8px 18px 18px 8px; color: white;
  background: linear-gradient(145deg, #2447b8, #4d70dc); cursor: pointer; box-shadow: 8px 12px 22px rgba(41,72,160,.15);
  transition: transform .2s ease, box-shadow .2s ease;
}
.book::before { content: ""; position: absolute; inset: 0 auto 0 8px; width: 2px; background: rgba(255,255,255,.28); }
.book:nth-child(2n) { background: linear-gradient(145deg, #087d75, #18a98a); }
.book:nth-child(3n) { background: linear-gradient(145deg, #703b9e, #9660c8); }
.book:hover { transform: translateY(-4px); box-shadow: 10px 18px 26px rgba(41,72,160,.22); }
.book-level { display: block; font-size: 28px; font-weight: 900; }
.book-name { display: block; margin-top: 8px; font-size: 13px; opacity: .86; }
.book-count { position: absolute; bottom: 14px; right: 14px; font-size: 12px; opacity: .85; }

.panel { padding: 24px; }
.filters { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 12px; margin: 18px 0 24px; }
.field { display: grid; gap: 7px; }
.field label { color: #59647a; font-size: 12px; font-weight: 700; }
select, input, textarea {
  width: 100%; border: 1px solid #ccd5e3; border-radius: 10px; color: var(--ink); background: white; outline: none;
}
select, input { min-height: 42px; padding: 8px 11px; }
textarea { padding: 14px; resize: vertical; }
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(48,86,211,.1); }
.question-list { display: grid; gap: 11px; }
.question-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; padding: 17px 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; transition: border .2s, transform .2s; }
.question-item:hover { border-color: #aebde9; transform: translateX(3px); }
.question-title { margin: 0 0 7px; font-size: 16px; font-weight: 750; }
.question-meta, .tag-row { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; color: var(--muted); font-size: 12px; }
.pill { display: inline-flex; align-items: center; min-height: 25px; padding: 2px 9px; border-radius: 99px; background: #edf1f8; color: #536078; font-size: 12px; }
.pill.ai { color: #6842ae; background: #f0eafa; }
.pill.official { color: #18745e; background: #e5f6f1; }
.pill.turtle { color: #9e6310; background: #fff2d9; }
.difficulty { align-self: center; font-weight: 700; color: var(--primary); }
.empty, .loading { padding: 42px; color: var(--muted); text-align: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 18px; border: 0; border-radius: 10px; color: white; background: var(--primary); font-weight: 750; cursor: pointer; transition: .2s ease; }
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
.btn.secondary { color: var(--primary); background: #eaf0ff; }
.btn.ghost { color: #536078; background: #edf1f6; }

.page-head { padding: 44px 0 24px; }
.page-head h1 { font-size: 40px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.actions { display: flex; align-items: center; gap: 12px; margin-top: 20px; }
.notice { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: #fff7e5; color: #835e15; }
.error { background: #fdecef; color: #a42e3d; }
.generated { margin-top: 22px; display: none; }
.generated.visible { display: block; }

.problem-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(390px, .82fr); gap: 22px; padding: 34px 0 50px; align-items: start; }
.problem-card { min-width: 0; padding: 26px; }
.problem-card h1 { font-size: 30px; margin-top: 6px; }
.problem-card h3 { margin: 26px 0 8px; }
.prose { white-space: pre-wrap; color: #3e485d; }
.sample-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
pre, code, .editor, .stdin-editor { font-family: "Cascadia Code", Consolas, monospace; }
pre { margin: 0; padding: 14px; overflow: auto; border-radius: 10px; background: #111a2b; color: #e8edf7; white-space: pre-wrap; }
.workspace { position: sticky; top: 88px; }
.editor-label { display: block; margin: 18px 0 7px; color: #59647a; font-size: 12px; font-weight: 700; }
.editor { min-height: 420px; tab-size: 4; line-height: 1.55; color: #e8edf7; background: #111a2b; border-color: #111a2b; }
.editor:focus { border-color: #516cba; }
.run-input { margin-top: 16px; }
.input-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.input-head label { color: #59647a; font-size: 13px; font-weight: 700; }
.btn.compact { min-height: 32px; padding: 5px 10px; font-size: 12px; white-space: nowrap; }
.stdin-editor { min-height: 104px; line-height: 1.5; }
.input-help { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.submit-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 14px; margin-top: 16px; }
.submit-row .field { flex: 1 0 110px; min-width: 110px; }
.execution-actions { display: grid; gap: 7px; }
.execution-actions .question-meta { justify-content: flex-end; }
.execution-buttons { display: flex; gap: 8px; }
.execution-buttons .btn { white-space: nowrap; }
.result { display: none; margin-top: 16px; padding: 15px; border-radius: 12px; background: #eef2f8; }
.result.visible { display: block; }
.result.AC, .result.OK { background: #e6f7f0; color: #12664f; }
.result.WA, .result.RE, .result.CE, .result.JE { background: #fdecef; color: #9d2939; }
.result.TLE, .result.MLE { background: #fff1d8; color: #8e5a0a; }
.result-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px 14px; margin-bottom: 7px; }
.result-heading > span { font-size: 12px; font-weight: 700; }
#message { white-space: pre-wrap; overflow-wrap: anywhere; }
.result-timing { margin-top: 6px; font-size: 12px; }
.result-note { margin: 10px 0 0; font-size: 12px; }
.run-output { display: grid; gap: 12px; margin-top: 12px; }
.run-output h3 { margin: 0 0 6px; font-size: 12px; font-weight: 700; }
.run-output pre { max-height: 260px; font-size: 13px; overflow-wrap: anywhere; }
.result [hidden] { display: none; }
.test-dots { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.test-dot { padding: 4px 9px; border-radius: 8px; background: rgba(255,255,255,.65); font-size: 12px; }
.canvas-wrap { display: none; margin-top: 16px; }
.canvas-wrap.visible { display: block; }
canvas { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 12px; background: white; }

footer { padding: 30px 0 44px; color: var(--muted); font-size: 13px; text-align: center; }

@media (max-width: 900px) {
  .hero, .problem-layout { grid-template-columns: 1fr; }
  .books { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: repeat(3, 1fr); }
  .workspace { position: static; }
}
@media (max-width: 600px) {
  .shell { width: min(100% - 20px, 1180px); }
  .nav-links { gap: 12px; font-size: 14px; }
  .hero { padding-top: 38px; }
  .books, .filters, .form-grid, .sample-grid { grid-template-columns: 1fr 1fr; }
  .question-item { grid-template-columns: 1fr; }
  .difficulty { justify-self: start; }
  .form-grid .wide { grid-column: 1 / -1; }
  .problem-card { padding: 18px; }
  .editor { min-height: 300px; }
  .execution-actions { flex: 1 1 220px; }
  .execution-actions .question-meta { justify-content: flex-start; }
  .execution-buttons .btn { flex: 1; }
  .canvas-wrap .section-head { flex-wrap: wrap; }
}
