:root {
  --bg: #f6f3ee;
  --bg-elevated: #ffffff;
  --bg-top: #241e1a;
  --text: #221c17;
  --text-muted: #6a6058;
  --text-on-dark: #e9e1d6;
  --border: #e3dbd0;
  --accent: #b87818;
  --accent-strong: #9a6210;
  --accent-soft: #fbefd9;
  --accent-text: #8a5608;
  --brown: #8a5230;
  --err: #b3261e;
  --shadow: 0 1px 2px rgba(40, 24, 10, .06), 0 8px 24px rgba(40, 24, 10, .08);
  --font: "Segoe UI", "Segoe UI Variable Text", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --radius: 6px;
  --radius-lg: 12px;

  /* The four notebook colours, plus empty boxes */
  --c-green: #3c9d4e;
  --c-yellow: #f0c43c;
  --c-orange: #ec8a2a;
  --c-red: #d4433b;
  --box-empty: #ffffff;
  --box-border: #cfc5b8;
  --box-future: #efe9e1;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --bg-elevated: #221e18;
    --bg-top: #110e0b;
    --text: #efe8de;
    --text-muted: #b0a596;
    --border: #3a332a;
    --accent: #eeaa28;
    --accent-strong: #f6bd4f;
    --accent-soft: #3a2c14;
    --accent-text: #f2bb55;
    --brown: #c98a5c;
    --err: #f2867c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --c-green: #4cb35e;
    --c-yellow: #f2cb4e;
    --c-orange: #f0973e;
    --c-red: #e2554c;
    --box-empty: #2b261f;
    --box-border: #574d40;
    --box-future: #1f1b16;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; outline: none; padding-top: 24px; padding-bottom: 48px; }
a { color: var(--accent-text); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.5rem, 4vw, 2rem); letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
p { margin: 0; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--text-muted); }
.small { font-size: .875rem; }

/* Top bar */
.top { background: var(--bg-top); color: var(--text-on-dark); padding-top: env(safe-area-inset-top); }
.top-row { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand img { image-rendering: pixelated; }
.wordmark { font-weight: 800; font-size: 1.2rem; letter-spacing: .01em; }
.w-a { color: #eeaa28; }
.w-b { color: #c98a5c; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.lang { display: flex; border: 1px solid rgba(255, 255, 255, .25); border-radius: var(--radius); overflow: hidden; }
.lang button { background: none; border: 0; color: var(--text-on-dark); font: inherit; font-size: .85rem; font-weight: 600; padding: 4px 10px; cursor: pointer; }
.lang button[aria-pressed="true"] { background: rgba(255, 255, 255, .16); color: #fff; }
.top .btn.ghost { color: var(--text-on-dark); border-color: rgba(255, 255, 255, .25); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border-radius: var(--radius); padding: 9px 16px; border: 1px solid transparent; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn.small { padding: 5px 10px; font-size: .875rem; }
.btn.primary { background: var(--accent); color: #1d1408; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.secondary { background: var(--bg-elevated); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--text-muted); }
.btn.ghost { background: none; color: var(--text-muted); border-color: var(--border); }
.btn.danger { background: none; color: var(--err); border-color: var(--border); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .lang button:focus-visible, a:focus-visible, .box:focus-visible, .chip:focus-visible, .seg button:focus-visible, .level:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Motto */
.motto { display: flex; align-items: center; gap: 12px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: var(--radius-lg); padding: 12px 16px; margin-bottom: 24px; font-weight: 600; color: var(--accent-text); }
.motto .boxes { display: flex; gap: 3px; flex: none; }
.motto .boxes i { width: 12px; height: 12px; border-radius: 2px; display: block; }

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; border: 1px solid var(--border); background: var(--bg-elevated); border-radius: var(--radius-lg); padding: 12px 16px; margin-bottom: 20px; }
.banner p { flex: 1 1 260px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 8px 0 12px; flex-wrap: wrap; }

/* Goal cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); gap: 16px; }
.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.card h3 a { color: inherit; text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.card .meta { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: .9rem; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.strip { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 3px; }
.strip .box { width: auto; }
.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); }
.badge.done { background: color-mix(in srgb, var(--c-green) 18%, transparent); color: var(--c-green); }

.empty { text-align: center; padding: 40px 16px; border: 2px dashed var(--border); border-radius: var(--radius-lg); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.empty img { image-rendering: pixelated; }

.finished { margin-top: 36px; }
.finished ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.finished li a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elevated); color: inherit; text-decoration: none; flex-wrap: wrap; }

/* Stacked colour bar */
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--box-future); }
.bar i { display: block; height: 100%; }

/* Boxes */
.box { appearance: none; border: 1px solid var(--box-border); background: var(--box-empty); border-radius: 3px; aspect-ratio: 1; padding: 0; position: relative; cursor: pointer; min-width: 0; }
.box.future { background: var(--box-future); border-style: dashed; cursor: default; }
.box.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.box.note::after { content: ""; position: absolute; right: 2px; top: 2px; width: 4px; height: 4px; border-radius: 50%; background: rgba(0, 0, 0, .55); }
.c-green, .box.c-green { background: var(--c-green); border-color: var(--c-green); }
.c-yellow, .box.c-yellow { background: var(--c-yellow); border-color: var(--c-yellow); }
.c-orange, .box.c-orange { background: var(--c-orange); border-color: var(--c-orange); }
.c-red, .box.c-red { background: var(--c-red); border-color: var(--c-red); }

.grid-wrap { overflow-x: auto; padding: 4px 4px 8px; margin: 0 -4px; }
.grid { display: grid; gap: 3px; }
.grid.rows { grid-template-columns: repeat(var(--per), minmax(0, 34px)); }
.grid.columns { grid-auto-flow: column; grid-template-rows: repeat(var(--per), 22px); grid-auto-columns: 22px; width: max-content; }
.grid.columns .box { aspect-ratio: auto; }

/* Goal page */
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; font-weight: 600; }
.goal-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.goal-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 16px 0; }
.stat { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.2; }
.stat span { font-size: .82rem; color: var(--text-muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 12px; font-size: .9rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.panel { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-top: 16px; }
.notes { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.notes li { display: grid; grid-template-columns: 6px 1fr; gap: 12px; }
.notes li > i { border-radius: 3px; }
.notes .when { font-size: .82rem; color: var(--text-muted); }
.notes .when b { color: var(--text); }
.notes p { overflow-wrap: anywhere; white-space: pre-wrap; }
.notes button { all: unset; cursor: pointer; display: block; }
.notes button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* Dialogs */
dialog { border: 0; padding: 0; border-radius: var(--radius-lg); background: var(--bg-elevated); color: var(--text); width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(20, 14, 8, .55); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.x { background: none; border: 0; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.dlg-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.file-btn { position: relative; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .92rem; border: 0; margin: 0; padding: 0; min-width: 0; }
.field .muted { font-weight: 400; }
input, textarea, select { font: inherit; font-weight: 400; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; width: 100%; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.inline { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.inline input { width: 110px; }
.count { align-self: flex-end; font-weight: 400; font-size: .8rem; }
.err { color: var(--err); font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 460px) { .row2 { grid-template-columns: 1fr; } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-weight: 600; font-size: .875rem; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
.seg { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button { flex: 1; font: inherit; font-weight: 600; font-size: .875rem; background: var(--bg); color: var(--text); border: 0; padding: 8px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }

.label-rows { display: flex; flex-direction: column; gap: 6px; }
.label-rows label { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: center; }
.label-rows i { width: 22px; height: 22px; border-radius: 4px; display: block; }

.levels { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.level { position: relative; display: flex; align-items: center; gap: 10px; border: 2px solid var(--border); border-radius: var(--radius); padding: 10px; cursor: pointer; font-weight: 600; font-size: .92rem; line-height: 1.25; }
.level input { position: absolute; opacity: 0; pointer-events: none; }
.level i { width: 26px; height: 26px; border-radius: 4px; flex: none; }
.level:has(input:checked) { border-color: var(--text); background: var(--bg); }
@media (max-width: 380px) { .levels { grid-template-columns: 1fr; } }

.foot { border-top: 1px solid var(--border); padding: 20px 0 calc(20px + env(safe-area-inset-bottom)); font-size: .875rem; color: var(--text-muted); }
.foot p + p { margin-top: 4px; }

@media (prefers-reduced-motion: no-preference) {
  .box { transition: transform .08s ease; }
  .box:not(.future):hover { transform: scale(1.12); }
}
.c-none { background: var(--box-border); }

/* Studio strip: way back to the IBS home page */
.studio-bar { background: rgba(0, 0, 0, .22); font-size: .8rem; }
.studio-bar .wrap { padding-top: 4px; padding-bottom: 4px; }
.studio-bar a { color: var(--text-on-dark); opacity: .85; text-decoration: none; font-weight: 600; }
.studio-bar a:hover { opacity: 1; text-decoration: underline; }

/* Header links */
.top-link { color: var(--text-on-dark); font-weight: 600; font-size: .9rem; text-decoration: none; }
.top-link:hover { text-decoration: underline; }
@media (max-width: 520px) { .top-link.hide-sm { display: none; } }

/* Ads (hidden until ads.js fills them) */
.ad { margin: 8px auto 24px; text-align: center; min-height: 90px; }
.ad-label { display: block; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }

/* Guide pages: one page, two languages */
html[lang="en"] [lang="lv"], html[lang="lv"] [lang="en"] { display: none !important; }
.article { max-width: 720px; }
.article h1 { margin-bottom: 8px; }
.article .lead { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 24px; }
.article h2 { margin: 32px 0 10px; font-size: 1.3rem; }
.article h3 { margin: 20px 0 6px; font-size: 1.05rem; }
.article p, .article ul, .article ol { margin: 0 0 14px; }
.article li { margin-bottom: 6px; }
.article .callout { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: var(--radius); margin: 20px 0; }
.scale { list-style: none; padding: 0; display: grid; gap: 6px; }
.scale li { display: grid; grid-template-columns: 18px 1fr; gap: 10px; align-items: start; margin: 0; }
.scale li i { width: 18px; height: 18px; border-radius: 4px; margin-top: 3px; }
.guide-list { list-style: none; padding: 0; display: grid; gap: 12px; }
.guide-list a { display: block; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-elevated); color: inherit; text-decoration: none; box-shadow: var(--shadow); }
.guide-list a:hover { border-color: var(--accent); }
.guide-list b { display: block; font-size: 1.1rem; margin-bottom: 4px; color: var(--text); }
.guide-list span { color: var(--text-muted); }
.more { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--border); }
.example-grid { display: grid; grid-template-columns: repeat(10, 22px); gap: 3px; margin: 12px 0 18px; }
.example-grid i { width: 22px; height: 22px; border-radius: 3px; display: block; }
.btn.small { white-space: nowrap; }
@media (max-width: 440px) { .with-cta .wordmark { display: none; } }

/* App layout with an ad sidebar on large screens */
.ad-side { display: none; }
@media (min-width: 1240px) {
  .layout { display: grid; grid-template-columns: minmax(0, 920px) 300px; gap: 24px; justify-content: center; }
  .layout > main.wrap { margin: 0; width: 100%; }
  .ad-side { display: block; padding-top: 24px; }
  .ad-side .ad { position: sticky; top: 16px; margin: 0; }
}
.ad-inline { margin: 28px auto; }
.layout { flex: 1; }
@media (min-width: 1240px) { .has-side .top .wrap, .has-side .foot .wrap, .has-side .layout + .wrap { max-width: 1276px; } }
