:root {
  --red: #b92735;
  --red-dark: #981f2b;
  --red-soft: #fdf0f1;
  --ink: #202c3c;
  --muted: #596579;
  --line: #e7e9ed;
  --green: #167c70;
  --blue: #315cc9;
  --radius: 18px;
  --sidebar-width: 252px;
  --nav-height: 72px;
}

/* Dasar */
* { box-sizing: border-box; }
html { scroll-padding-top: 20px; }
body { margin: 0; background: #fff; color: var(--ink); font: 16px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { cursor: pointer; }
a { color: inherit; }
img, svg { max-width: 100%; }
img { display: block; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
main:focus { outline: none; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { color: var(--ink); overflow-wrap: anywhere; }
h1 { margin-bottom: 14px; font-size: 34px; line-height: 1.25; letter-spacing: -.8px; }
h2 { margin-bottom: 14px; font-size: 23px; line-height: 1.35; letter-spacing: -.4px; }
h3 { margin-bottom: 9px; font-size: 18px; line-height: 1.4; }
p { margin-bottom: 16px; color: var(--muted); overflow-wrap: anywhere; }
.skip { position: fixed; top: -100px; left: 12px; z-index: 100; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.skip:focus { top: 12px; }

/* Navigasi */
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; flex-direction: column; width: var(--sidebar-width); padding: 28px 22px; overflow-y: auto; border-right: 1px solid var(--line); background: #fff; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; font-size: 22px; font-weight: 800; letter-spacing: -.7px; }
.brand > span:last-child { min-width: 0; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: 0; line-height: 1.5; }
.brand-mark { position: relative; display: grid; flex-shrink: 0; place-content: center; width: 42px; height: 46px; border-radius: 14px; background: var(--red); color: #fff; font-size: 28px; }
.brand-mark span { position: absolute; top: 0; right: 7px; color: #ffd481; }
.nav-label { margin: 36px 12px 14px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1.5px; }
#nav { display: grid; gap: 7px; }
#nav a { display: flex; align-items: center; gap: 14px; min-height: 48px; padding: 12px 15px; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 15px; font-weight: 600; }
#nav a.active { background: var(--red-soft); color: var(--red); }
.svg-icon { display: inline-block; flex-shrink: 0; width: 23px; height: 23px; vertical-align: middle; }
.sidebar-note { margin-top: auto; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: #fafafa; }
.sidebar-note strong { display: block; margin-top: 12px; font-size: 14px; }
.sidebar-note p { margin: 7px 0 13px; font-size: 13px; }
.flag { display: block; width: 34px; height: 24px; border: 1px solid #dedede; border-radius: 3px; background: linear-gradient(#c92c3e 50%, #fff 50%); }
.version { margin: 18px 8px 0; color: var(--muted); font-size: 11px; }

/* Halaman */
.layout { min-width: 0; margin-left: var(--sidebar-width); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 88px; padding: 18px 36px; border-bottom: 1px solid var(--line); }
.topbar > div:first-child { min-width: 0; }
.topbar strong { display: block; margin-top: 3px; font-size: 19px; }
.eyebrow { color: var(--red); font-size: 11px; font-weight: 750; letter-spacing: 1.3px; }
.top-actions { display: flex; flex-shrink: 0; align-items: center; gap: 16px; }
.connection { max-width: 190px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.connection::before { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--green); content: ""; }
.connection.offline::before { background: #9b640c; }
.avatar { flex-shrink: 0; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--red-soft); color: var(--red); font-weight: 700; }
main { width: 100%; max-width: 1260px; margin: 0 auto; padding: 28px 36px 36px; }
main > section, main > div { min-width: 0; }
.intro { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.intro > div { min-width: 0; }
.intro h1 { margin-bottom: 6px; font-size: 28px; }
.intro p { margin: 0; font-size: 15px; }
.intro > .pill { flex-shrink: 0; }

/* Beranda */
.hero { display: grid; grid-template-columns: 1.15fr 1fr; align-items: center; gap: 24px; padding: 28px; border: 1px solid var(--line); border-radius: 22px; background: linear-gradient(110deg, #fff 55%, #fff8f5); }
.hero > div { min-width: 0; }
.hero h1, .hero h2 { margin: 16px 0 14px; font-size: clamp(28px, 3vw, 38px); line-height: 1.2; letter-spacing: -.8px; }
.hero p { max-width: 440px; font-size: 16px; }
.hero-art img { width: 100%; height: auto; max-height: 275px; object-fit: contain; }
.hero-bottom { margin-top: 16px; color: var(--muted); font-size: 12px; }

/* Tombol */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-width: 44px; min-height: 46px; padding: 10px 17px; border: 1px solid var(--red); border-radius: 11px; background: var(--red); color: #fff; text-align: center; text-decoration: none; font-size: 14px; font-weight: 650; line-height: 1.4; }
.button.secondary { border-color: #d9dde4; background: #fff; color: var(--ink); }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.pill { display: inline-block; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--muted); font-size: 12px; line-height: 1.4; }
.pill.red { border-color: #f5d3d7; background: var(--red-soft); color: var(--red); }
.text-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--red); text-decoration: none; font-size: 14px; font-weight: 650; }
.small { color: var(--muted); font-size: 13px; }

/* Kartu */
.section-title { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; margin: 26px 0 14px; }
.section-title h2 { margin: 0; font-size: 21px; }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.bottom-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.card { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.card > .pill { margin-bottom: 14px; }
.card p { margin-bottom: 16px; font-size: 15px; }
.card .button { min-height: 44px; padding: 9px 14px; font-size: 14px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head > .pill { max-width: 55%; }
.icon-tile { display: grid; flex-shrink: 0; place-content: center; width: 44px; height: 44px; margin-bottom: 16px; border-radius: 12px; background: var(--red-soft); color: var(--red); }
.icon-tile.red { background: var(--red-soft); color: var(--red); }
.icon-tile.blue { background: #eef3ff; color: var(--blue); }
.icon-tile.green { background: #eaf6f2; color: var(--green); }
.icon-tile.gold { background: #fff6df; color: #805b12; }
.meta { margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.notice { margin: 16px 0; padding: 13px 16px; border: 1px solid var(--line); border-radius: 11px; background: #f7f8fa; color: var(--muted); font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }

/* Perkembangan belajar */
.progress-track { height: 9px; margin: 15px 0; overflow: hidden; border-radius: 10px; background: #eef0f3; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); }
.steps { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.steps span { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 12px; }
.score-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.score-grid strong { display: block; color: var(--ink); font-size: 30px; line-height: 1.3; }
.score-grid .small { display: block; margin-top: 5px; }
.muted-badge { display: inline-block; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f7f7f8; color: var(--muted); font-size: 13px; }
.empty { padding: 20px 0; text-align: center; }
.empty p { max-width: 440px; margin: 12px auto 18px; }
.empty > .svg-icon { width: 30px; height: 30px; color: var(--red); }

/* Filter */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.tabs button { min-height: 44px; padding: 9px 16px; border: 1px solid #d9dde4; border-radius: 10px; background: #fff; color: var(--muted); font-size: 14px; line-height: 1.4; }
.tabs button[aria-pressed="true"] { border-color: #efc6cc; background: var(--red-soft); color: var(--red); font-weight: 650; }

/* Formulir profil */
.form { display: grid; gap: 15px; }
.form label { display: grid; gap: 7px; font-size: 14px; font-weight: 650; }
.form input, .form select, .form textarea { width: 100%; min-width: 0; min-height: 46px; padding: 11px 12px; border: 1px solid #cbd1da; border-radius: 10px; background: #fff; color: var(--ink); font-size: 16px; }
.form input::placeholder, .form textarea::placeholder { color: #687488; opacity: 1; }
.form textarea { min-height: 140px; resize: vertical; }
.form .check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.form .check input { flex-shrink: 0; width: 20px; min-height: 20px; height: 20px; margin: 0; padding: 0; accent-color: var(--red); }
.form p { margin: 0; }
.topic { display: flex; align-items: flex-start; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.topic:last-child { border: 0; }
.topic b { flex-shrink: 0; padding: 4px 10px; border-radius: 8px; background: var(--red-soft); color: var(--red); }
.topic span { font-size: 14px; }

/* Dialog */
dialog { width: min(560px, calc(100% - 28px)); max-height: 88vh; max-height: 88dvh; margin: auto; padding: 24px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 20px; background: #fff; color: var(--ink); box-shadow: 0 20px 70px #18213026; }
dialog::backdrop { background: #18213070; }
.dialog-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.icon-button { display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #f7f8fa; color: var(--ink); font-size: 25px; line-height: 1; }
#dialog-content { min-width: 0; }
#dialog-content > h2 { margin-bottom: 12px; }
#dialog-content > .pill { margin-bottom: 14px; }
#dialog-content > .button { margin-top: 12px; }

/* Leaderboard */
table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 14px; }
caption { padding: 8px 0 12px; text-align: left; }
th, td { padding: 12px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--muted); font-size: 12px; font-weight: 650; }
th:first-child, td:first-child { width: 22%; }
th:last-child, td:last-child { width: 20%; text-align: right; }

/* Notifikasi dan footer */
.toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: 50%; z-index: 50; width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #fff; text-align: center; font-size: 14px; opacity: 0; pointer-events: none; transform: translateX(-50%); }
.toast.show { opacity: 1; }
footer { padding: 18px 24px; border-top: 1px solid var(--line); color: var(--muted); text-align: center; font-size: 12px; }
footer p { margin-bottom: 5px; }
footer small { font-size: 11px; }

/* Laptop dan tablet */
@media (max-width: 1100px) {
  :root { --sidebar-width: 215px; }
  .sidebar { padding: 24px 15px; }
  .topbar { padding: 18px 24px; }
  main { padding: 24px; }
  .hero { gap: 18px; padding: 24px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bottom-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* HP */
@media (max-width: 760px) {
  .sidebar { inset: auto 0 0; width: 100%; height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px)); padding: 5px 8px calc(5px + env(safe-area-inset-bottom, 0px)); overflow: visible; border-top: 1px solid var(--line); border-right: 0; background: #fff; }
  .sidebar .brand, .nav-label, .sidebar-note, .version { display: none; }
  #nav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; gap: 3px; height: 100%; }
  #nav a { flex-direction: column; justify-content: center; gap: 4px; min-width: 0; min-height: 56px; padding: 6px 2px; border-radius: 10px; font-size: 11px; line-height: 1.2; }
  #nav .svg-icon { width: 22px; height: 22px; }
  .layout { margin-left: 0; padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px)); }
  .topbar { gap: 12px; min-height: 78px; padding: 14px max(18px, env(safe-area-inset-right, 0px)) 14px max(18px, env(safe-area-inset-left, 0px)); }
  .topbar .eyebrow { display: block; max-width: 170px; font-size: 9px; letter-spacing: .8px; }
  .topbar strong { font-size: 18px; }
  .top-actions { gap: 10px; }
  .connection { max-width: 110px; font-size: 11px; }
  main { padding: 20px max(18px, env(safe-area-inset-right, 0px)) 28px max(18px, env(safe-area-inset-left, 0px)); }
  .intro { align-items: flex-start; gap: 12px; margin-bottom: 18px; }
  .intro h1 { font-size: 24px; }
  .intro p { font-size: 14px; }
  .intro > .pill { margin-top: 3px; font-size: 11px; }
  .hero { grid-template-columns: 1fr; gap: 16px; padding: 22px; border-radius: 18px; }
  .hero-art { grid-row: 1; }
  .hero-art img { max-height: 180px; }
  .hero h1, .hero h2 { font-size: 30px; }
  .hero p { font-size: 16px; }
  .grid, .grid.two, .bottom-grid { grid-template-columns: 1fr; gap: 14px; }
  .card { padding: 20px; }
  .section-title { margin-top: 24px; }
  .section-title h2 { font-size: 20px; }
  .score-grid { gap: 8px; }
  .score-grid .card { padding: 14px 10px; border-radius: 12px; }
  .score-grid strong { font-size: 26px; }
  .score-grid .small { font-size: 12px; line-height: 1.4; }
  .steps { gap: 7px; }
  dialog { padding: 20px; border-radius: 18px; }
  .toast { bottom: calc(var(--nav-height) + 14px + env(safe-area-inset-bottom, 0px)); width: calc(100% - 32px); }
  footer { padding: 16px 18px; font-size: 11px; }
}

/* HP berlayar sempit */
@media (max-width: 380px) {
  main { padding-right: 14px; padding-left: 14px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .top-actions { margin-left: auto; }
  .intro { flex-direction: column; gap: 8px; }
  .intro h1 { font-size: 23px; }
  .hero { padding: 18px; }
  .hero h1, .hero h2 { font-size: 27px; }
  .hero .button-row { flex-direction: column; }
  .hero .button { width: 100%; }
  .card { padding: 18px; }
  .card-head { flex-wrap: wrap; }
  .card-head > .pill { max-width: 100%; }
  .score-grid strong { font-size: 23px; }
  .tabs button { padding-right: 12px; padding-left: 12px; }
}

/* Hover untuk mouse */
@media (hover: hover) and (pointer: fine) {
  #nav a:hover { background: #f6f7f9; }
  #nav a.active:hover { background: var(--red-soft); }
  .button:hover { border-color: var(--red-dark); background: var(--red-dark); }
  .button.secondary:hover { border-color: #c8ced8; background: #f7f8fa; }
  .text-link:hover { text-decoration: underline; }
  .card:hover { box-shadow: 0 6px 20px #18213008; }
}

/* Animasi ringan */
@media (prefers-reduced-motion: no-preference) {
  .button, .card, #nav a, .tabs button { transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease; }
  .toast { transition: opacity .2s ease; }
  .progress-track span { transition: width .25s ease; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}