/* ==========================================================================
   Themes — every visual decision is a token so a theme is just a token set
   plus a few decorative rules. Switch with <html data-theme="…">.
     teras  : "Teras Rumah" — bright & playful, colours taken from the front
              terrace at Langsep 16 (butter walls, peach tiles, orchids, periwinkles)
     modern : clean, neutral, follows the OS light/dark preference
     papan  : "Papan Tulis" — chalkboard green, chalk handwriting, wood frame
     buku   : "Buku Kotak" — graph-paper exercise book, ink blue, red margin
   ========================================================================== */
:root,
[data-theme='modern'] {
  --bg: #f6f7fb;
  --bg-pattern: none;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #171a23;
  --muted: #5d6475;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #e0e7ff;
  --border: #e2e5ee;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 4px 16px rgb(16 24 40 / 0.06);
  --radius: 14px;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Inter', system-ui, sans-serif;
  --display-weight: 800;
  --mat: #4f46e5;
  --fis: #0891b2;
  --kim: #c2410c;
  --card-border: 1px solid var(--border);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]),
  [data-theme='modern'] {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #20242f;
    --text: #eceef4;
    --muted: #9aa1b2;
    --accent: #818cf8;
    --accent-text: #0f1117;
    --accent-soft: #272a4a;
    --border: #2a2f3c;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    --mat: #a5b4fc;
    --fis: #67e8f9;
    --kim: #fdba74;
    color-scheme: dark;
  }
}

[data-theme='papan'] {
  --bg: #233a30;
  --bg-pattern: radial-gradient(ellipse at 20% 10%, rgb(255 255 255 / 0.05), transparent 50%),
    radial-gradient(ellipse at 80% 60%, rgb(255 255 255 / 0.04), transparent 55%),
    radial-gradient(ellipse at 40% 90%, rgb(0 0 0 / 0.15), transparent 60%);
  --surface: #2b463a;
  --surface-2: #34544a;
  --text: #f4f1e6;
  --muted: #c3cfc3;
  --accent: #f6d55c;
  --accent-text: #1d2f27;
  --accent-soft: rgb(246 213 92 / 0.16);
  --border: rgb(244 241 230 / 0.28);
  --shadow: 0 2px 0 rgb(0 0 0 / 0.25);
  --radius: 6px;
  --font-body: 'Kalam', 'Comic Neue', 'Segoe Print', cursive;
  --font-display: 'Kalam', cursive;
  --display-weight: 700;
  --mat: #f6d55c;
  --fis: #8fd3fe;
  --kim: #ffa8a8;
  --card-border: 2px dashed rgb(244 241 230 / 0.35);
  color-scheme: dark;
}

[data-theme='teras'] {
  --bg: #fff8e7;
  /* faint peach wall tiles, like the terrace wainscot */
  --bg-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='46' height='46'%3E%3Cpath d='M0 .5H46M.5 0V46' stroke='%23f4b68e' stroke-opacity='.35' stroke-width='1.5'/%3E%3Cpath d='M14 30c4-10 14-10 18-2' fill='none' stroke='%23f3a77c' stroke-opacity='.3' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  --surface: #ffffff;
  --surface-2: #fff1d6;
  --text: #3b2416;
  --muted: #7a5040;
  --accent: #d6246e;
  --accent-text: #ffffff;
  --accent-soft: #ffe0ec;
  --border: #f6d3b4;
  --shadow: 0 6px 0 rgb(240 173 46 / 0.35), 0 10px 24px rgb(214 36 110 / 0.08);
  --radius: 18px;
  --font-body: 'Nunito', system-ui, sans-serif;
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --display-weight: 700;
  --mat: #c2185b;
  --fis: #1565c0;
  --kim: #2e7d32;
  --card-border: 2px solid #ffe3a8;
  color-scheme: light;
}

[data-theme='buku'] {
  --bg: #fdfbf3;
  --bg-pattern: linear-gradient(rgb(66 133 244 / 0.13) 1px, transparent 1px),
    linear-gradient(90deg, rgb(66 133 244 / 0.13) 1px, transparent 1px);
  --surface: #fffef9;
  --surface-2: #f3efe0;
  --text: #1c2a5a;
  --muted: #56608a;
  --accent: #d6336c;
  --accent-text: #ffffff;
  --accent-soft: #fde2ea;
  --border: #cfd6ea;
  --shadow: 3px 3px 0 #1c2a5a;
  --radius: 4px;
  --font-body: 'Patrick Hand', 'Segoe Print', cursive;
  --font-display: 'Patrick Hand', cursive;
  --display-weight: 400;
  --mat: #1d4ed8;
  --fis: #047857;
  --kim: #b91c1c;
  --card-border: 2px solid #1c2a5a;
  color-scheme: light;
}

/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: var(--bg-pattern);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}
[data-theme='buku'] body { background-size: 24px 24px; font-size: 18px; }
[data-theme='teras'] body { font-size: 17px; }
[data-theme='papan'] body { background-attachment: fixed; font-size: 17px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------------------------------------------------------------- header */
/* The header is the front terrace of Pak Sunarto's house (public/teras.svg), in every theme. */
.site-header {
  padding: 64px 0 200px;
  background: var(--hero-tint, linear-gradient(transparent, transparent)), url('/teras.svg') 50% 100% / cover no-repeat, #fff4cf;
}
[data-theme='papan'] .site-header { --hero-tint: linear-gradient(rgb(35 58 48 / 0.55), rgb(35 58 48 / 0.35)); border-top: 14px solid #7a5230; }
[data-theme='buku'] .site-header { --hero-tint: linear-gradient(rgb(253 251 243 / 0.25), rgb(253 251 243 / 0.25)); border-bottom: 3px solid #1c2a5a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .site-header,
  [data-theme='modern'] .site-header { --hero-tint: linear-gradient(rgb(15 17 23 / 0.45), rgb(15 17 23 / 0.2)); }
}
.brand {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 16px 20px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: var(--card-border); border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow); backdrop-filter: blur(4px); max-width: 720px;
}
.brand img { width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--accent); background: var(--surface-2); }
.brand h1 { margin: 0; font-family: var(--font-display); font-weight: var(--display-weight); font-size: clamp(1.6rem, 3.5vw, 2.4rem); line-height: 1.1; }
[data-theme='papan'] .brand h1 { text-shadow: 0 0 1px rgb(255 255 255 / 0.6); letter-spacing: 0.5px; }
.brand p { margin: 4px 0 0; color: var(--muted); }
.brand .grow { flex: 1 1 260px; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: var(--radius); border: var(--card-border);
  background: var(--surface); text-decoration: none; cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: #c92a2a; }
.btn.small { padding: 5px 10px; font-size: 0.9em; }
.btn:disabled { opacity: 0.5; cursor: default; }
.yt-btn { background: #e62117; color: #fff; border-color: #e62117; }
[data-theme='buku'] .btn { box-shadow: 2px 2px 0 var(--text); }

/* theme switcher */
.themes { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.themes button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.themes button[aria-pressed='true'] { border-color: var(--accent); }
.swatch-teras { background: linear-gradient(135deg, #ffc94d 0 33%, #ff5fa2 33% 66%, #4caf50 66%); }
.swatch-modern { background: linear-gradient(135deg, #fff 50%, #4f46e5 50%); }
.swatch-papan { background: linear-gradient(135deg, #233a30 50%, #f6d55c 50%); }
.swatch-buku { background: linear-gradient(135deg, transparent 50%, #d6336c 50%), repeating-linear-gradient(0deg, #9db8ee 0 1px, #fdfbf3 1px 6px); }

[data-theme='teras'] .brand h1 { color: var(--accent); }
[data-theme='teras'] .brand img { border-color: #ffc94d; box-shadow: 0 0 0 4px #ff5fa2; }
[data-theme='teras'] .card { border-bottom: 6px solid var(--subj, #ffc94d); }
[data-theme='teras'] .card:hover { transform: translateY(-4px) rotate(-0.6deg); }
[data-theme='teras'] .pl-code { background: var(--subj, var(--accent)); color: #fff; border-radius: 50% 50% 46% 54% / 55% 45% 55% 45%; }
[data-theme='teras'] .chip { border-color: #ffd98a; font-weight: 700; }
[data-theme='teras'] .chip.subj-Matematika[aria-pressed='true'],
[data-theme='teras'] .chip.subj-Fisika[aria-pressed='true'],
[data-theme='teras'] .chip.subj-Kimia[aria-pressed='true'] { background: var(--subj); border-color: var(--subj); }
[data-theme='teras'] .tag { color: #fff; background: var(--subj, var(--accent)); border-color: transparent; }
[data-theme='teras'] .section-title { color: var(--text); }
[data-theme='teras'] .section-title::before { content: ''; width: 1.1em; height: 1.1em; align-self: center; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-20 -20 40 40'%3E%3Cg fill='%23ff5fa2'%3E%3Cpath id='p' d='M0 0C-7-9-6-17 0-19C6-17 7-9 0 0z'/%3E%3Cuse href='%23p' transform='rotate(72)'/%3E%3Cuse href='%23p' transform='rotate(144)'/%3E%3Cuse href='%23p' transform='rotate(216)'/%3E%3Cuse href='%23p' transform='rotate(288)'/%3E%3C/g%3E%3Ccircle r='4' fill='%23ffe066'/%3E%3C/svg%3E") center / contain no-repeat; }
[data-theme='teras'] .search-box input { border: 3px solid #ffc94d; }
[data-theme='teras'] .btn.primary { box-shadow: 0 4px 0 #9e1450; }
[data-theme='teras'] .btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #9e1450; }

/* ---------------------------------------------------------------- search */
.search-panel { margin: -44px 0 8px; display: grid; gap: 14px; position: relative; }
.search-box { position: relative; }
.search-box input {
  width: 100%; padding: 16px 20px 16px 52px; font-size: 1.15rem;
  border-radius: calc(var(--radius) + 4px); border: var(--card-border); background: var(--surface); box-shadow: var(--shadow);
}
.search-box input::placeholder { color: var(--muted); }
.search-box svg { position: absolute; left: 18px; top: 50%; translate: 0 -50%; color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: var(--card-border); background: var(--surface); padding: 6px 14px; border-radius: 999px; cursor: pointer;
  display: inline-flex; gap: 6px; align-items: baseline; white-space: nowrap;
}
.chip small { color: var(--muted); }
.chip[aria-pressed='true'] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip[aria-pressed='true'] small { color: inherit; opacity: 0.8; }

/* ---------------------------------------------------------------- welcome note */
.welcome {
  margin: 26px 0 0; padding: 20px 24px; display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: start;
  background: var(--surface); border: var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.welcome-avatar { width: 72px; height: 72px; border-radius: 50%; border: 3px solid var(--accent); }
.welcome h2 { margin: 0 0 6px; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.4rem; }
.welcome p { margin: 0 0 10px; max-width: 72ch; }
.welcome-signature { font-family: var(--font-display); font-weight: var(--display-weight); color: var(--accent); margin: 4px 0 0 !important; }
/* Teras: a note taped to the terrace wall */
[data-theme='teras'] .welcome { position: relative; background: #fffdf3; border: 2px solid #ffe3a8; transform: rotate(-0.4deg); }
[data-theme='teras'] .welcome::before {
  content: ''; position: absolute; top: -12px; left: 50%; width: 110px; height: 24px; translate: -50% 0; rotate: -3deg;
  background: rgb(255 95 162 / 0.55); border-radius: 3px;
}
[data-theme='teras'] .welcome-avatar { border-color: #ffc94d; box-shadow: 0 0 0 4px #ff5fa2; }
[data-theme='papan'] .welcome-signature { color: var(--accent); }
@media (max-width: 560px) {
  .welcome { grid-template-columns: 1fr; padding: 16px; gap: 10px; }
  .welcome-avatar { width: 56px; height: 56px; }
}

/* ---------------------------------------------------------------- playlists shelf */
.section-title { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.35rem; margin: 26px 0 12px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.section-title .muted { font-family: var(--font-body); font-size: 0.95rem; font-weight: 400; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.pl-card {
  min-width: 0; text-align: left; cursor: pointer; border: var(--card-border); background: var(--surface); border-radius: var(--radius);
  padding: 12px 14px; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; align-items: center; box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.pl-card:hover { transform: translateY(-2px); }
[data-theme='buku'] .pl-card:hover { transform: rotate(-1deg); }
.pl-card[aria-pressed='true'] { outline: 3px solid var(--accent); outline-offset: 1px; }
.pl-code {
  grid-row: span 2; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.6rem; line-height: 1;
  width: 58px; height: 58px; display: grid; place-items: center; border-radius: calc(var(--radius) - 2px);
  background: var(--surface-2); color: var(--subj, var(--accent));
}
[data-theme='papan'] .pl-code { background: transparent; border: 2px solid currentColor; border-radius: 50%; }
.pl-name { font-weight: 700; line-height: 1.2; }
.pl-count { color: var(--muted); font-size: 0.9em; }
.subj-Matematika { --subj: var(--mat); }
.subj-Fisika { --subj: var(--fis); }
.subj-Kimia { --subj: var(--kim); }

/* ---------------------------------------------------------------- results */
.results-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; margin: 28px 0 14px; }
.results-head .section-title { margin: 0; }
.results-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, .input {
  padding: 8px 12px; border-radius: var(--radius); border: var(--card-border); background: var(--surface);
}
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card {
  background: var(--surface); border: var(--card-border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column; cursor: pointer; transition: transform 0.12s ease; text-align: left; padding: 0;
}
.card:hover { transform: translateY(-3px); }
[data-theme='buku'] .card:nth-child(odd):hover { transform: rotate(-0.8deg); }
[data-theme='buku'] .card:nth-child(even):hover { transform: rotate(0.8deg); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
[data-theme='papan'] .thumb img { filter: saturate(0.85) contrast(1.05); }
.badge {
  position: absolute; right: 8px; bottom: 8px; background: rgb(0 0 0 / 0.78); color: #fff; font: 600 0.78rem/1 system-ui, sans-serif;
  padding: 4px 6px; border-radius: 4px;
}
.badge.left { left: 8px; right: auto; background: var(--accent); color: var(--accent-text); }
.card-body { padding: 12px 14px 14px; display: grid; gap: 8px; flex: 1; align-content: start; }
.card-title { margin: 0; font-weight: 700; font-size: 1.02rem; line-height: 1.3; }
[data-theme='papan'] .card-title, [data-theme='buku'] .card-title { font-size: 1.15rem; font-weight: 400; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 0.86rem; }
.tag {
  font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--subj, var(--text));
  border: 1px solid var(--border); font-weight: 600;
}
.empty { padding: 60px 20px; text-align: center; color: var(--muted); border: var(--card-border); border-radius: var(--radius); background: var(--surface); }
.more { display: flex; justify-content: center; margin: 26px 0 50px; }
.skeleton .thumb, .skeleton .card-title { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.skeleton .card-title { height: 2.6em; border-radius: 4px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- player dialog */
dialog.player {
  width: min(1000px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: var(--card-border);
  border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgb(0 0 0 / 0.5);
}
dialog.player::backdrop { background: rgb(0 0 0 / 0.7); }
.player-frame { aspect-ratio: 16 / 9; background: #000; }
.player-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-body { padding: 14px 18px 18px; display: grid; gap: 10px; }
.player-body h2 { margin: 0; font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.35rem; }
.player-notes { white-space: pre-wrap; margin: 0; }
.player-nav { display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; }
.player-close { position: absolute; top: 8px; right: 8px; z-index: 2; background: rgb(0 0 0 / 0.6); color: #fff; border: 0; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 20px; }

footer.site-footer { padding: 24px 0 40px; color: var(--muted); font-size: 0.9rem; border-top: 1px solid var(--border); }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card-body { padding: 8px 10px 10px; }
  .card-title { font-size: 0.92rem; }
  .shelf { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; padding: 2px 16px 10px; margin: 0 -16px; }
  .pl-card { flex: 0 0 190px; scroll-snap-align: start; }
  .pl-code { width: 46px; height: 46px; font-size: 1.25rem; }
  .site-header { padding: 20px 0 130px; background-position: 56% 100%; }
  .brand { padding: 12px 14px; gap: 12px; }
  .brand img { width: 48px; height: 48px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
