:root {
  --bg: #0b0d10;
  --panel: #12161b;
  --line: #232a33;
  --text: #e9edf2;
  --muted: #8b96a5;
  --accent: #4c8dff;
  --snap: #ff4d9d;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
        "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

/* ---------- views ---------- */
.cropapp {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.home {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-t) + 34px) 22px calc(24px + var(--safe-b));
  overflow-y: auto;
}
.home__brand { font-size: 34px; font-weight: 700; letter-spacing: 1px; }
.home__sub { color: var(--muted); margin: 8px 0 30px; font-size: 14px; }
.home__card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 16px;
  color: var(--text);
}
.home__card:active { transform: scale(.99); filter: brightness(1.15); }
.home__card-icon { font-size: 26px; color: var(--accent); }
.home__card-text { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.home__card-title { font-size: 16px; font-weight: 600; }
.home__card-desc { font-size: 12.5px; color: var(--muted); }
.home__card-arrow { color: var(--muted); font-size: 22px; }
.home__soon { margin-top: 30px; display: flex; flex-direction: column; gap: 10px; }
.home__soon-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: 14px;
  background: #10141a;
  border: 1px dashed var(--line);
  color: #7b8795;
  font-size: 14px;
}
.home__soon-item .tag { font-size: 12px; color: #5d6876; }

/* ---------- top bar ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 16px) 6px calc(var(--safe-l) + 16px);
}
.brand { font-weight: 600; letter-spacing: .5px; }
.readout {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: .2px;
}
.ghost {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  padding: 6px 2px 6px 10px;
}
.back {
  appearance: none;
  border: 0;
  background: none;
  color: var(--text);
  width: 40px;
  height: 40px;
  margin-left: -10px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  cursor: pointer;
}
.back svg { display: block; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  touch-action: none;
  overflow: hidden;
}
.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}
.empty__art {
  font-size: 44px;
  color: #2f3a47;
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.empty h1 { font-size: 19px; font-weight: 600; margin: 0; }
.empty__sub { margin: 0 0 14px; color: var(--muted); font-size: 14px; max-width: 280px; }
.empty__tip { margin: 6px 0 0; color: #5d6876; font-size: 12px; }

.busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(11, 13, 16, .72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  font-size: 14px;
  color: #cfd6df;
}
.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid rgba(255,255,255,.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toolbar ---------- */
.toolbar {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px calc(var(--safe-r) + 12px) calc(8px + var(--safe-b)) calc(var(--safe-l) + 12px);
}

.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 9px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  appearance: none;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #171c22;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.chip.is-on {
  background: rgba(76, 141, 255, .16);
  border-color: rgba(76, 141, 255, .55);
  color: #cfe0ff;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.25fr;
  gap: 8px;
}

.btn {
  appearance: none;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #1a2029;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 0 12px;
}
.btn:active { transform: scale(.985); filter: brightness(1.15); }
.btn--primary {
  background: linear-gradient(180deg, #5b97ff, #3d7bf0);
  border-color: #3d7bf0;
  color: #fff;
  font-weight: 600;
}
.btn--wide { width: 100%; margin-top: 10px; }

/* ---------- sheets ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(5, 7, 10, .66);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
.card {
  width: 100%;
  max-width: 460px;
  background: #12161b;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px 16px calc(16px + var(--safe-b));
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } }
.card__head { font-weight: 600; margin-bottom: 12px; }
.preview {
  background: #0a0c0f;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  justify-content: center;
  max-height: 42dvh;
}
.preview img {
  max-width: 100%;
  max-height: calc(42dvh - 20px);
  border-radius: 6px;
  object-fit: contain;
  display: block;
}
.seg {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  background: #0e1216;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
}
.seg__btn {
  flex: 1;
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  padding: 9px 0;
  border-radius: 9px;
}
.seg__btn.is-on { background: #1d2733; color: var(--text); }
.sheet__hint { margin: 10px 0 0; text-align: center; font-size: 12.5px; color: var(--muted); }

.boot-error {
  position: fixed;
  top: calc(var(--safe-t) + 8px);
  left: 8px;
  right: 8px;
  z-index: 90;
  padding: 11px 13px;
  border-radius: 12px;
  background: #4a1218;
  border: 1px solid #8c2b36;
  color: #ffd9de;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-line;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.boot-error--warn {
  background: #3a2c0e;
  border-color: #8a6a1d;
  color: #ffe6b0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translateX(-50%);
  background: rgba(28, 34, 42, .96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13.5px;
  padding: 9px 15px;
  border-radius: 999px;
  z-index: 30;
  max-width: 86vw;
  text-align: center;
  animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 6px); } }
