/* =========================================================
   MIMI TYPH STUDIO — Mini App
   Cocoa / cream / caramel, same palette as the chat cards
   ========================================================= */

:root {
  --bg: #120e0b;
  --surface: #1b1511;
  --surface-2: #241c16;
  --surface-3: #2e241c;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f4ece2;
  --muted: #a89a8c;
  --faint: #74675b;
  --accent: #d4a373;
  --accent-soft: rgba(212, 163, 115, 0.16);
  --accent-ink: #1d130b;
  --danger: #ff6b81;
  --ok: #6ecf97;
  --r-xl: 24px;
  --r-lg: 18px;
  --r-md: 13px;
  --r-sm: 10px;
  --dock-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body { background: var(--bg); }
body {
  color: var(--text);
  font: 15px/1.4 var(--font);
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(138, 90, 54, 0.28), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }
img { display: block; max-width: 100%; }

.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.i-bolt { width: 15px; height: 15px; fill: var(--accent); stroke: none; }

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Header ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(18, 14, 11, 0.82);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-align: left; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
  background: #fff; border: 2px solid var(--accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { font-size: 10px; font-weight: 700; letter-spacing: 3px; color: var(--accent); }
.credit-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  background: var(--accent-soft); border: 1px solid rgba(212, 163, 115, 0.35);
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
}

/* ---------------- Views ---------------- */
.views { flex: 1; padding: 16px 16px calc(var(--dock-h) + 28px + env(safe-area-inset-bottom)); }
.view { display: none; animation: fade 0.22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 2px 14px; }
.view-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.3px; }
.view-head p { color: var(--muted); font-size: 13px; margin-top: 2px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: 16px;
}
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }

.count-pill {
  padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--line-strong);
}
.count-pill.accent { background: var(--accent-soft); border-color: rgba(212, 163, 115, 0.4); color: var(--accent); letter-spacing: 1px; }

/* ---------------- Buttons ---------------- */
.btn-primary {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 15px 18px; border-radius: var(--r-lg);
  background: linear-gradient(180deg, #e2b484, var(--accent));
  color: var(--accent-ink); font-weight: 800; font-size: 16px;
  box-shadow: 0 8px 24px rgba(212, 163, 115, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.12s ease, opacity 0.2s;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; }
.btn-primary .cost { font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: rgba(29, 19, 11, 0.14); }
.btn-primary.compact { width: auto; padding: 10px 18px; font-size: 14px; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line-strong);
  font-weight: 600;
}
.btn-ghost.small { padding: 8px 13px; font-size: 13px; }
.btn-ghost:active { background: var(--surface-3); }
.btn-mini { margin-left: auto; padding: 5px 10px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 800; }

/* ---------------- Stage (create) ---------------- */
.stage {
  position: relative; overflow: hidden;
  aspect-ratio: 1 / 1; width: 100%;
  border-radius: var(--r-xl);
  border: 1px solid var(--line);
  background:
    radial-gradient(60% 55% at 50% 42%, rgba(212, 163, 115, 0.22), transparent 70%),
    repeating-radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 22px),
    var(--surface);
}
.stage-bg {
  position: absolute; inset: -30px; background-size: cover; background-position: center;
  filter: blur(28px) brightness(0.55); opacity: 0; transition: opacity 0.4s;
}
.stage.has-img .stage-bg { opacity: 1; }
.stage-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; animation: fade 0.35s ease; }
.stage-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 6px;
}
.stage-logo {
  width: 104px; height: 104px; border-radius: 50%; overflow: hidden; background: #fff;
  border: 3px solid var(--accent); margin-bottom: 10px;
  box-shadow: 0 0 0 10px rgba(212, 163, 115, 0.08), 0 16px 40px rgba(0, 0, 0, 0.5);
}
.stage-logo img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.18); }
.stage-title { font-weight: 800; font-size: 18px; }
.stage-hint { color: var(--muted); font-size: 13px; }

.stage-busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(18, 14, 11, 0.62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.busy-title { font-weight: 700; font-size: 15px; text-align: center; padding: 0 20px; }

.ring { position: relative; width: 118px; height: 118px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255, 255, 255, 0.1); stroke-width: 9; }
.ring-fill {
  fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset 0.6s ease;
}
.ring-pct, .ring-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 26px; font-variant-numeric: tabular-nums;
}
.ring.spin svg { animation: spin 1.4s linear infinite; }
.ring.spin .ring-fill { stroke-dashoffset: 250; }
@keyframes spin { to { transform: rotate(270deg); } }

.status-line {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 4px 14px; color: var(--muted); font-size: 13px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 10px rgba(110, 207, 151, 0.6); }
.dot.busy { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------------- Composer ---------------- */
.composer { display: flex; flex-direction: column; gap: 12px; }
.composer-head { display: flex; justify-content: space-between; align-items: center; }
.counter { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
textarea, input[type="number"], input[type="text"] {
  width: 100%; border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: var(--bg); padding: 12px 14px; outline: none; resize: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
textarea { min-height: 88px; }
textarea:focus, input:focus { border-color: rgba(212, 163, 115, 0.6); box-shadow: 0 0 0 3px rgba(212, 163, 115, 0.12); }
textarea::placeholder, input::placeholder { color: var(--faint); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 8px 13px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line-strong); white-space: nowrap;
}
.chip:active, .chip.on { background: var(--accent-soft); border-color: rgba(212, 163, 115, 0.5); color: var(--accent); }

/* ---------------- Segmented ---------------- */
.segmented { display: flex; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.segmented button { padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--muted); }
.segmented button.active { background: var(--accent); color: var(--accent-ink); }

/* ---------------- Feed ---------------- */
.feed { display: flex; flex-direction: column; gap: 14px; }
.post { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); overflow: hidden; }
.post-media { position: relative; aspect-ratio: 1 / 1; background: var(--surface-2); }
.post-media img { width: 100%; height: 100%; object-fit: cover; }
.post-body { padding: 12px 14px 12px; display: flex; flex-direction: column; gap: 6px; }
.post-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 12px;
}
.post-author { color: var(--text); font-weight: 700; font-size: 13px; }
.post-time { margin-left: auto; }
.post-title { font-weight: 800; font-size: 16px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); font-size: 13px; }
.post-actions { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.act {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; font-weight: 700;
}
.act svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.act.liked { color: var(--danger); border-color: rgba(255, 107, 129, 0.35); }
.act.liked svg { fill: var(--danger); }
.act.push { margin-left: auto; }
.act.danger { color: var(--danger); }

/* ---------------- Works grid ---------------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.work { position: relative; aspect-ratio: 1 / 1; border-radius: var(--r-lg); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.work img { width: 100%; height: 100%; object-fit: cover; }
.work::after { content: ""; position: absolute; inset: 55% 0 0; background: linear-gradient(transparent, rgba(0, 0, 0, 0.7)); }
.work-badge {
  position: absolute; left: 8px; bottom: 8px; z-index: 1;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700;
  background: rgba(18, 14, 11, 0.7); border: 1px solid var(--line-strong);
}
.work-badge.pub { color: var(--accent); border-color: rgba(212, 163, 115, 0.5); }

/* ---------------- Profile ---------------- */
.balance { display: flex; align-items: center; gap: 18px; }
.ring.big { width: 124px; height: 124px; flex: none; }
.ring.big .ring-num { font-size: 36px; }
.balance-text { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; min-width: 0; }
.balance-text strong { font-size: 20px; }
.balance-text .btn-ghost { margin-top: 8px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 14px 12px; display: flex; flex-direction: column; gap: 2px;
}
.tile strong { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 12px; }
.rows { padding: 4px 16px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; font-size: 14px; }
.row + .row { border-top: 1px solid var(--line); }
.row > span:first-child { color: var(--muted); }
.row code { font-size: 13px; color: var(--text); }
.ok { color: var(--ok); font-weight: 700; }
.fineprint { color: var(--faint); font-size: 12px; text-align: center; margin: 16px 12px 0; }

/* ---------------- Admin ---------------- */
.form { display: flex; flex-direction: column; gap: 10px; }

/* ---------------- Gate / empty ---------------- */
.gate { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 60px 20px; }
.gate h1 { font-size: 22px; }
.gate p { color: var(--muted); }
.empty {
  grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 14px;
  padding: 36px 16px; border: 1px dashed var(--line-strong); border-radius: var(--r-xl);
}
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--r-xl); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------- Dock ---------------- */
.dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 30;
  width: min(440px, calc(100% - 32px)); height: var(--dock-h);
  display: flex; justify-content: space-around; align-items: center;
  background: rgba(30, 23, 18, 0.88); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line-strong); border-radius: 22px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
.dock-btn {
  position: relative; width: 52px; height: 44px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; color: var(--faint);
  transition: color 0.2s, background 0.2s;
}
.dock-btn.active { color: var(--accent); background: var(--accent-soft); }

/* ---------------- Sheet ---------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center; animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  position: relative; width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-strong); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 0 auto 12px; }
.sheet-close {
  position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); font-size: 14px;
}
.sheet-close.static { position: static; flex: none; }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.sheet-photo { width: 100%; border-radius: var(--r-lg); background: var(--surface-2); }
.sheet-title { font-size: 18px; font-weight: 800; padding-right: 36px; }
.prompt-box { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; font-size: 14px; color: var(--muted); word-break: break-word; }
.btn-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; }
.comments { display: flex; flex-direction: column; gap: 8px; }
.comment { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; }
.comment.commit_prompt { border-color: rgba(212, 163, 115, 0.45); }
.comment-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.comment-head b { color: var(--text); }
.tag { color: var(--accent); font-weight: 700; }
.comment-text { font-size: 14px; word-break: break-word; }
.composer-inline { display: flex; flex-direction: column; gap: 8px; }
.composer-inline .toggle { display: flex; gap: 6px; }

/* ---------------- Snake ---------------- */
.snake-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(8, 6, 5, 0.97);
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fadeIn 0.2s ease;
}
.snake-box { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 12px; }
.snake-head { display: flex; align-items: center; gap: 12px; }
.snake-title { display: block; font-weight: 800; letter-spacing: 2px; }
.snake-sub { font-size: 11px; color: var(--accent); letter-spacing: 1px; }
.snake-scores { margin-left: auto; display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.snake-scores b { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.snake-status {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.canvas-wrap { position: relative; border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--line-strong); }
#snakeCanvas { display: block; width: 100%; height: auto; touch-action: none; }
.canvas-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: rgba(18, 14, 11, 0.78);
}
.canvas-overlay h3 { letter-spacing: 2px; }
.canvas-overlay p { color: var(--muted); }
.dpad {
  display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 52px);
  gap: 8px; justify-content: center;
  grid-template-areas: ". up ." "left mid right" ". down .";
}
.dpad-btn { border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line-strong); font-size: 18px; color: var(--muted); }
.dpad-btn:active { background: var(--accent-soft); color: var(--accent); }
.dpad-btn.up { grid-area: up; } .dpad-btn.down { grid-area: down; }
.dpad-btn.left { grid-area: left; } .dpad-btn.right { grid-area: right; } .dpad-btn.mid { grid-area: mid; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-h) + 28px + env(safe-area-inset-bottom)); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 40px); padding: 11px 16px; border-radius: 14px;
  background: var(--surface-3); border: 1px solid var(--line-strong); font-size: 14px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); transition: all 0.25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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