:root {
  --paper: #f6f1e8; --card: #fffdf8; --ink: #1d1a26; --muted: #6b6578; --line: #e6dfd2;
  --accent: #5b4bff; --accent-ink: #ffffff; --warn: #c2410c; --ok: #15803d;
  --shadow: 0 1px 2px rgba(29,26,38,.06), 0 6px 20px rgba(29,26,38,.07);
  --r: 20px; --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16141f; --card: #201d2c; --ink: #f3effa; --muted: #a59fb5; --line: #2e2a3d;
    --accent: #8b7dff; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* the mark: four tiles, one of them still to be made */
.mark { display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 26px; height: 26px; vertical-align: -6px; }
.mark i { border-radius: 5px; background: var(--accent); }
.mark i:nth-child(2) { background: #ff8a5b; } .mark i:nth-child(3) { background: #2bb673; }
.mark i:nth-child(4) { background: transparent; border: 2px dashed var(--muted); }
.mark.big { width: 64px; height: 64px; gap: 7px; } .mark.big i { border-radius: 12px; }
.boot { display: grid; place-items: center; height: 100vh; }
.boot .mark i { animation: pop 1.2s ease-in-out infinite; } .boot .mark i:nth-child(2) { animation-delay: .15s; }
.boot .mark i:nth-child(3) { animation-delay: .3s; } .boot .mark i:nth-child(4) { animation-delay: .45s; }
@keyframes pop { 50% { transform: scale(.82); } }

.wrap { max-width: 560px; margin: 0 auto; padding: calc(14px + var(--safe-t)) 16px calc(28px + var(--safe-b)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.brand { font-weight: 800; font-size: 22px; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; font-size: 20px; }
h1 { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; margin: 6px 0 8px; }
h2 { font-size: 18px; margin: 26px 0 10px; }
p.lead { color: var(--muted); margin: 0 0 18px; }
.muted { color: var(--muted); } .small { font-size: 14px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; transition: transform .12s ease, opacity .12s; }
.btn:active { transform: scale(.97); } .btn[disabled] { opacity: .5; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.soft { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.btn.danger { background: transparent; color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.btn.wide { width: 100%; }
.field { display: block; margin: 0 0 14px; }
.field span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.input, textarea.input { width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 17px; }
textarea.input { min-height: 120px; resize: vertical; line-height: 1.4; }
.err { color: var(--warn); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.center-screen .card { width: 100%; max-width: 420px; }

/* home grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px 12px; }
.tile { border: 0; background: none; padding: 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 7px; }
.tile .face { width: 74px; height: 74px; border-radius: 22px; display: grid; place-items: center; font-size: 36px;
  background: var(--c, var(--accent)); box-shadow: 0 8px 18px color-mix(in srgb, var(--c, var(--accent)) 35%, transparent), inset 0 -3px 0 rgba(0,0,0,.12);
  transition: transform .15s ease; position: relative; }
.tile:active .face { transform: scale(.92) rotate(-2deg); }
.tile .name { font-size: 13px; font-weight: 600; line-height: 1.2; max-width: 96px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile.new .face { background: transparent; border: 2.5px dashed var(--muted); box-shadow: none; color: var(--muted); font-size: 34px; font-weight: 300; }
.tile.enter { animation: rise .45s cubic-bezier(.2,.9,.3,1.3) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.9); } }

.banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 16px; background: color-mix(in srgb, var(--accent) 10%, var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line)); margin-bottom: 18px; font-size: 14px; }
.banner b { display: block; font-size: 15px; } .banner .x { margin-left: auto; background: none; border: 0; font-size: 20px; color: var(--muted); min-width: 36px; min-height: 36px; }

/* tool view: full screen */
.toolview { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--paper); z-index: 10; animation: slide .25s ease both; }
@keyframes slide { from { transform: translateY(24px); opacity: 0; } }
.toolbar { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 12px 8px; border-bottom: 1px solid var(--line); background: var(--paper); }
.toolbar .title { flex: 1; font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; }
.toolbar .title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar .dot { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; font-size: 16px; background: var(--c); flex: none; }
.toolframe { flex: 1; width: 100%; border: 0; background: var(--paper); }
.fixbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px calc(10px + var(--safe-b)); background: color-mix(in srgb, var(--warn) 12%, var(--card)); border-top: 1px solid var(--line); font-size: 14px; }
.fixbar span { flex: 1; }

/* sheets (dialogs) */
.scrim { position: fixed; inset: 0; background: rgba(15,12,25,.42); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease both; }
@keyframes fade { from { opacity: 0; } }
.sheet { width: 100%; max-width: 560px; background: var(--card); border-radius: 26px 26px 0 0; padding: 10px 18px calc(22px + var(--safe-b)); box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  animation: up .28s cubic-bezier(.2,.9,.3,1.1) both; max-height: 88vh; overflow: auto; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 6px; font-size: 20px; }
.sheet .row { display: flex; gap: 10px; margin-top: 16px; } .sheet .row .btn { flex: 1; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 54px; border: 0; background: none; text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 17px; }
.menu-item:last-child { border-bottom: 0; } .menu-item .em { width: 28px; text-align: center; font-size: 20px; }
.menu-item.danger { color: var(--warn); }
.versions { list-style: none; margin: 10px 0 0; padding: 0; }
.versions li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.versions li div { flex: 1; min-width: 0; } .versions small { display: block; color: var(--muted); }
.versions .now { font-size: 12px; font-weight: 700; color: var(--ok); }

/* builder */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 9px 14px; font-size: 14px; min-height: 40px; }
.chip:active { transform: scale(.96); }
.building { text-align: center; padding: 30px 0 10px; }
.forge { position: relative; width: 120px; height: 120px; margin: 0 auto 18px; }
.forge i { position: absolute; width: 50px; height: 50px; border-radius: 15px; background: var(--accent); animation: shuffle 2.4s cubic-bezier(.6,0,.3,1) infinite; }
.forge i:nth-child(1) { left: 0; top: 0; }
.forge i:nth-child(2) { left: 64px; top: 0; background: #ff8a5b; animation-delay: -.6s; }
.forge i:nth-child(3) { left: 64px; top: 64px; background: #2bb673; animation-delay: -1.2s; }
.forge i:nth-child(4) { left: 0; top: 64px; background: transparent; border: 3px dashed var(--muted); animation-delay: -1.8s; }
@keyframes shuffle { 0%,100% { transform: none; } 25% { transform: translate(64px,0); } 50% { transform: translate(64px,64px); } 75% { transform: translate(0,64px); } }
.progress-line { font-weight: 700; font-size: 18px; } .progress-sub { color: var(--muted); font-size: 14px; margin-top: 4px; min-height: 20px; }

.settings .card { margin-bottom: 14px; }
.code-big { font: 800 40px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .12em; text-align: center; padding: 14px 0 6px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 14px; z-index: 80; font-size: 15px; animation: up .25s ease both; max-width: calc(100% - 32px); }
.install-steps { margin: 10px 0 0; padding-left: 22px; } .install-steps li { margin: 6px 0; }
.empty-note { text-align: center; color: var(--muted); font-size: 14px; margin-top: 18px; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
