[hidden] { display: none !important; }
:root {
  --bg: #f3f7ff;
  --paper: #ffffff;
  --ink: #1f2a44;
  --muted: #5b6785;
  --line: #d8e1f2;
  --blue: #2b6cb0;
  --blue-l: #dbeafe;
  --orange: #ff8a3d;
  --green: #2f9e6e;
  --pink: #e64980;
  --yellow: #ffd43b;
  --violet: #7048e8;
  --radius: 18px;
  --shadow: 0 4px 14px rgba(31, 42, 68, .10);
  --font: "Nunito", ui-rounded, "Segoe UI Rounded", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --topbar: 58px;
  --stage: #e9f4ff;
  --chip: #eef3fb;
  --step-num: #c9d6ec;
  --tool-bg: #ffffff;
  --on-bg: #fff4ec;
  --tip-bg: #fff9db;
  --tip-ink: #a26a00;
  --tpl-bg: #fbfdff;
  --topbar-bg: var(--blue);
  --overlay: rgba(20, 28, 50, .45);
  --hero: linear-gradient(135deg, #2b6cb0, #7048e8);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1626;
  --paper: #1a2336;
  --ink: #e8eefc;
  --muted: #9fb0d0;
  --line: #2f3d5a;
  --blue-l: #1e3256;
  --shadow: 0 4px 14px rgba(0, 0, 0, .45);
  --stage: #1a2335;
  --chip: #243049;
  --step-num: #3a4a6b;
  --tool-bg: #212c43;
  --on-bg: #3a2a1f;
  --tip-bg: #2e2a17;
  --tip-ink: #ffd43b;
  --tpl-bg: #212c43;
  --topbar-bg: #16213a;
  --overlay: rgba(0, 0, 0, .6);
  --hero: linear-gradient(135deg, #1f4f86, #4f32b0);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; color: inherit; }
input, select { font-family: inherit; }

/* ---------- top bar ---------- */
.topbar {
  height: var(--topbar);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  background: var(--topbar-bg);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
.brand .logo { font-size: 26px; }
.brand .title { font-weight: 800; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn {
  background: rgba(255,255,255,.16); border: 0; color: #fff;
  width: 42px; height: 42px; border-radius: 12px; font-size: 20px; cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }
.input-badge {
  background: rgba(255,255,255,.18); padding: 6px 10px; border-radius: 999px;
  font-size: 14px; font-weight: 700; white-space: nowrap;
}

main#app { height: calc(100% - var(--topbar)); position: relative; }
.screen { position: absolute; inset: 0; overflow: auto; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 12px 16px; min-height: 48px;
  background: var(--paper); box-shadow: var(--shadow);
  font-weight: 800; font-size: 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn.primary { background: var(--orange); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border: 2px solid var(--line); }
.btn.on { outline: 3px solid var(--orange); outline-offset: -3px; background: var(--on-bg); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.topbar .btn.small { background: #fff; color: var(--blue); box-shadow: none; }

/* ---------- home ---------- */
.home { padding: 18px 16px 40px; max-width: 1100px; margin: 0 auto; }
.hero {
  background: var(--hero);
  color: #fff; border-radius: 26px; padding: 22px 22px 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.hero h1 { margin: 0 0 6px; font-size: clamp(26px, 5vw, 40px); }
.hero p { margin: 0; font-size: 17px; opacity: .95; max-width: 640px; }
.hero .grid-deco {
  position: absolute; inset: 0; pointer-events: none; opacity: .14;
  background-image: linear-gradient(#fff 1px, transparent 1px), linear-gradient(90deg, #fff 1px, transparent 1px);
  background-size: 28px 28px;
}
.process { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; position: relative; }
.process .p-step {
  background: rgba(255,255,255,.18); border-radius: 14px; padding: 8px 12px;
  font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px;
}
.process .p-arrow { align-self: center; opacity: .8; font-weight: 800; }

.section-title { font-size: 20px; font-weight: 800; margin: 26px 4px 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  background: var(--paper); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  border: 0; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px;
  border-top: 8px solid var(--c, var(--blue)); min-height: 150px;
}
.card:active { transform: scale(.98); }
.card .emoji { font-size: 40px; }
.card h3 { margin: 0; font-size: 19px; }
.card p { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.35; }
.card .tag { align-self: flex-start; font-size: 12px; font-weight: 800; color: var(--c); background: color-mix(in srgb, var(--c) 14%, var(--paper)); padding: 3px 8px; border-radius: 99px; }

/* ---------- picker overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet {
  background: var(--paper); border-radius: 24px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
  width: min(760px, 100%); max-height: 100%; overflow: auto; padding: 20px;
}
.sheet h2 { margin: 0 0 4px; }
.sheet .sub { color: var(--muted); margin: 0 0 14px; }
.sheet .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }
.sheet input[type=text] {
  width: 100%; font-size: 20px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--tool-bg); color: var(--ink);
  user-select: text; -webkit-user-select: text;
}
.tpl-group { margin-bottom: 14px; }
.tpl-group h4 { margin: 8px 2px; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .05em; }
.tpl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.tpl {
  border: 2px solid var(--line); background: var(--tpl-bg); border-radius: 16px; padding: 10px 8px;
  cursor: pointer; text-align: center; font-weight: 800; font-size: 15px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.tpl .emoji { font-size: 34px; }
.tpl small { color: var(--muted); font-weight: 600; font-size: 12px; }
.tpl:active { transform: scale(.97); }

/* ---------- editor ---------- */
.editor { display: flex; flex-direction: column; overflow: hidden; }
.steps {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px;
  background: var(--paper); border-bottom: 1px solid var(--line); overflow-x: auto; flex: none;
}
.step {
  border: 0; background: var(--chip); border-radius: 14px; padding: 6px 12px 6px 6px; cursor: pointer;
  display: flex; align-items: center; gap: 6px; font-weight: 800; white-space: nowrap; min-height: 44px;
}
.step .num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--step-num); color: #fff;
  display: grid; place-items: center; font-size: 14px;
}
.step .ico { font-size: 20px; }
.step.active { background: var(--blue); color: #fff; }
.step.active .num { background: #fff; color: var(--blue); }
.step.done .num { background: var(--green); }
.steps .arrow { color: #9fb0cf; font-weight: 800; }

.work { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.stage { flex: 1; position: relative; min-height: 0; background: var(--stage); overflow: hidden; }
.tools {
  flex: none; background: var(--paper); border-top: 1px solid var(--line);
  padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  max-height: 42vh; overflow-y: auto;
}
.tools .group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tools .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }
.tools .label { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; width: 100%; }
.tool {
  border: 2px solid var(--line); background: var(--tool-bg); border-radius: 14px; min-width: 52px; min-height: 52px;
  padding: 4px 10px; font-weight: 800; font-size: 13px; cursor: pointer;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.tool .ti { font-size: 22px; line-height: 1; }
.tool.on { border-color: var(--orange); background: var(--on-bg); box-shadow: 0 0 0 2px var(--orange) inset; }
.tool:active { transform: scale(.96); }

.tip {
  width: 100%; background: var(--tip-bg); border-radius: 12px; padding: 8px 12px; font-size: 14.5px; line-height: 1.35;
  display: flex; gap: 8px; align-items: flex-start;
}
.tip b { color: var(--tip-ink); }
.hint-bubble {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  background: rgba(31,42,68,.85); color: #fff; padding: 8px 14px; border-radius: 999px;
  font-weight: 800; font-size: 15px; pointer-events: none; white-space: nowrap; z-index: 2; max-width: 92%;
  overflow: hidden; text-overflow: ellipsis;
}

@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  .work { flex-direction: row; }
  .tools {
    width: 300px; max-height: none; border-top: 0; border-left: 1px solid var(--line);
    align-content: flex-start; order: -1; border-right: 1px solid var(--line); border-left: 0;
  }
}

/* palette */
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--paper); cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0,0,0,.15);
}
.swatch.on { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.08); }
.swatch.custom {
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); position: relative; overflow: hidden;
}
.swatch.custom input { position: absolute; inset: -10px; opacity: 0; cursor: pointer; width: 60px; height: 60px; }

/* sliders */
.slider { display: flex; flex-direction: column; gap: 2px; min-width: 180px; flex: 1; }
.slider span { font-size: 13px; font-weight: 800; color: var(--muted); }
.slider input { width: 100%; accent-color: var(--orange); height: 36px; touch-action: none; cursor: pointer; }
.slider span b { color: var(--ink); }

/* canvas */
canvas.sketch, canvas.gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
canvas.overlay2d { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(40px);
  background: #1f2a44; color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700;
  box-shadow: 0 4px 18px rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.12);
  opacity: 0; transition: .25s; z-index: 50; pointer-events: none; max-width: 92vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* gallery */
.gallery { padding: 16px; max-width: 1100px; margin: 0 auto; }
.g-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.g-item { background: var(--paper); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.g-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--stage); display: block; }
.g-item .meta { padding: 8px 10px; }
.g-item .meta b { display: block; }
.g-item .meta small { color: var(--muted); }
.g-item .acts { display: flex; gap: 6px; padding: 0 8px 8px; }
.g-item .acts .btn { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 18px; }

/* school */
.school-tabs { display: flex; gap: 6px; padding: 8px 10px; background: var(--paper); border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
.quiz-opts { display: flex; gap: 10px; flex-wrap: wrap; }
.quiz-opt { border: 3px solid var(--line); border-radius: 14px; background: var(--tool-bg); padding: 6px; cursor: pointer; }
.quiz-opt canvas { display: block; width: 96px; height: 96px; }
.quiz-opt.right { border-color: var(--green); background: color-mix(in srgb, var(--green) 18%, var(--paper)); }
.quiz-opt.wrong { border-color: var(--pink); background: color-mix(in srgb, var(--pink) 18%, var(--paper)); }
.views-mini { display: flex; gap: 10px; flex-wrap: wrap; }
.views-mini figure { margin: 0; text-align: center; font-size: 12px; font-weight: 800; color: var(--muted); }
.views-mini canvas { display: block; width: 84px; height: 84px; background: #fff; border: 2px solid var(--line); border-radius: 10px; }
.views-mini figure.ok canvas { border-color: var(--green); }
.views-mini figure.bad canvas { border-color: var(--pink); }
.score { font-weight: 800; font-size: 18px; }

.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.settings-row input[type=checkbox] { width: 28px; height: 28px; accent-color: var(--orange); }
.legend { font-size: 13.5px; color: var(--muted); line-height: 1.4; }

/* jezik i tema u gornjoj traci */
.top-controls { display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; background: rgba(255,255,255,.16); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: #fff; font-weight: 800; font-size: 13px;
  min-width: 38px; height: 32px; border-radius: 999px; cursor: pointer;
}
.seg button.on { background: #fff; color: var(--blue); }
.sheet .seg { background: var(--chip); }
.sheet .seg button { color: var(--ink); }
.sheet .seg button.on { background: var(--blue); color: #fff; }
.theme-switch { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; position: relative; font-size: 16px; }
.theme-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.theme-switch .track {
  width: 46px; height: 26px; border-radius: 999px; background: rgba(255,255,255,.3); position: relative; transition: background .2s;
}
.theme-switch .knob {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s;
}
.theme-switch input:checked + .track { background: #7048e8; }
.theme-switch input:checked + .track .knob { transform: translateX(20px); }
.theme-switch input:focus-visible + .track { outline: 3px solid var(--yellow); outline-offset: 2px; }
.sheet .theme-switch .track { background: var(--step-num); }
.sheet .theme-switch input:checked + .track { background: #7048e8; }

/* izabrani nameštaj */
.sel-box { width: 100%; border: 2px solid var(--orange); background: var(--on-bg); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.sel-title { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.sel-title .ti { font-size: 24px; }
.furn-grid { width: 100%; }
.furn-grid .tool { width: 84px; min-height: 64px; font-size: 12px; text-align: center; line-height: 1.1; }
.furn-grid .tool .ti { font-size: 26px; }

@media (max-width: 520px) {
  .input-badge { display: none; }
  .theme-switch .sun, .theme-switch .moon { display: none; }
  .hint-bubble { white-space: normal; text-align: center; border-radius: 14px; font-size: 13.5px; width: max-content; max-width: 92%; }
  .brand .title { font-size: 17px; }
  .tool { min-width: 48px; min-height: 48px; padding: 3px 7px; font-size: 12px; }
  .step .lbl { display: none; }
}

/* let kroz objekat */
.fly-ui { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.fly-joy {
  position: absolute; left: 18px; bottom: 18px; width: 128px; height: 128px; border-radius: 50%;
  background: rgba(31,42,68,.35); border: 3px solid rgba(255,255,255,.7); pointer-events: auto; touch-action: none;
  display: grid; place-items: center; backdrop-filter: blur(2px);
}
.fly-stick { width: 56px; height: 56px; border-radius: 50%; background: #fff; box-shadow: 0 3px 10px rgba(0,0,0,.35); pointer-events: none; transition: transform .05s; }
.fly-side { position: absolute; right: 12px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
.fly-btn {
  border: 0; border-radius: 14px; min-width: 64px; min-height: 52px; padding: 4px 8px; cursor: pointer; touch-action: none;
  background: rgba(255,255,255,.92); color: #1f2a44; font-weight: 800; font-size: 12px; box-shadow: 0 3px 10px rgba(0,0,0,.25);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.fly-btn .ti { font-size: 20px; line-height: 1; }
.fly-btn.on { background: var(--orange); color: #fff; }
.fly-btn.fly-exit { background: #e03131; color: #fff; }
.fly-help {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: rgba(31,42,68,.85); color: #fff;
  padding: 7px 14px; border-radius: 999px; font-weight: 800; font-size: 13.5px; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 520px) {
  .fly-joy { width: 108px; height: 108px; left: 12px; bottom: 12px; }
  .fly-stick { width: 46px; height: 46px; }
  .fly-btn { min-width: 54px; min-height: 44px; }
  .fly-btn .tl { display: none; }
  .fly-help { white-space: normal; text-align: center; border-radius: 14px; font-size: 12.5px; }
}

/* galerija: uvoz i izvoz */
.g-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.g-head .section-title { margin: 12px 4px; }
.g-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.g-item .acts .btn.ghost { flex: 0 0 44px; padding: 8px 4px; }
.gallery > .legend { margin: 0 4px 14px; }
.sheet .seg button { padding: 0 12px; }

/* zadaci i značke */
.badge-bar { position: relative; height: 34px; border-radius: 999px; background: var(--chip); overflow: hidden; margin: 0 0 16px; }
.badge-bar .badge-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #ffd43b, #ff8a3d); border-radius: 999px; transition: width .4s; }
.badge-bar span { position: relative; display: grid; place-items: center; height: 100%; font-weight: 800; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.badge { display: flex; gap: 12px; align-items: center; background: var(--paper); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); border: 2px solid transparent; opacity: .75; }
.badge .b-ico { flex: none; width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; background: var(--chip); filter: grayscale(1); }
.badge b { display: block; font-size: 16px; }
.badge p { margin: 2px 0; color: var(--muted); font-size: 13.5px; line-height: 1.3; }
.badge small { font-weight: 800; color: var(--muted); }
.badge.got { opacity: 1; border-color: #ffd43b; }
.badge.got .b-ico { background: linear-gradient(135deg, #fff3bf, #ffd43b); filter: none; box-shadow: 0 2px 8px rgba(240, 140, 0, .35); }
.badge.got small { color: var(--green); }

/* ---------- doživljaj: prelazi, pokreti i sitnice ---------- */
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes sheetIn { from { opacity: 0; transform: translateY(18px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes heroShift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-8px) rotate(4deg); } }
.screen { animation: screenIn .32s cubic-bezier(.2, .8, .2, 1); }
.overlay { animation: fadeIn .18s ease-out; backdrop-filter: blur(3px); }
.sheet { animation: sheetIn .26s cubic-bezier(.2, .9, .3, 1.2); }
.hero { background-size: 220% 220%; animation: heroShift 14s ease-in-out infinite; }
.hero h1 { text-shadow: 0 3px 12px rgba(0, 0, 0, .18); }
.cards .card { transition: transform .18s ease, box-shadow .18s ease; }
@media (hover: hover) {
  .cards .card:hover { transform: translateY(-4px); box-shadow: 0 10px 26px rgba(31, 42, 68, .16); }
  .tool:hover { border-color: color-mix(in srgb, var(--orange) 55%, var(--line)); }
  .tpl:hover { transform: translateY(-2px); border-color: var(--orange); }
}
.card .emoji { display: inline-block; animation: floaty 4s ease-in-out infinite; }
.cards .card:nth-child(2) .emoji { animation-delay: -1s; }
.cards .card:nth-child(3) .emoji { animation-delay: -2s; }
.cards .card:nth-child(4) .emoji { animation-delay: -3s; }
.tool, .btn, .tpl, .step { transition: transform .12s ease, background-color .15s ease, border-color .15s ease, box-shadow .15s ease; }
.tool.on { animation: none; }
.toast { box-shadow: 0 10px 30px rgba(0, 0, 0, .35); }
.toast.show { transition: opacity .2s ease, transform .35s cubic-bezier(.2, 1.4, .4, 1); }
.stage { background: radial-gradient(ellipse at 50% 30%, color-mix(in srgb, var(--stage) 70%, #fff) 0%, var(--stage) 70%); }
canvas.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
@media (prefers-reduced-motion: reduce) {
  .screen, .sheet, .overlay, .hero, .card .emoji { animation: none !important; }
}
