/* ---------------------------------------------------------------
   Muse Console — design tokens
   Mirrors the iOS app's Liquid Glass language: glassEffect() cards
   with continuous rounded corners, system accent blue, SF-style
   type hierarchy (primary / secondary / tertiary), spring-ish
   motion, and centered glass alert cards for feedback.
------------------------------------------------------------------ */

:root {
  --accent: #007AFF;
  --accent-rgb: 0, 122, 255;
  --green: #34C759;
  --orange: #FF9500;
  --red: #FF3B30;

  --bg-canvas: #f2f2f7;
  --text-primary: #1c1c1e;
  --text-secondary: rgba(60, 60, 67, 0.6);
  --text-tertiary: rgba(60, 60, 67, 0.32);

  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-bg-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.65);
  --hairline: rgba(60, 60, 67, 0.13);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.04);

  --radius-card: 20px;
  --radius-alert: 28px;
  --radius-pill: 999px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #0A84FF;
    --bg-canvas: #000000;
    --text-primary: #f2f2f7;
    --text-secondary: rgba(235, 235, 245, 0.6);
    --text-tertiary: rgba(235, 235, 245, 0.32);

    --glass-bg: rgba(28, 28, 30, 0.58);
    --glass-bg-strong: rgba(36, 36, 38, 0.78);
    --glass-border: rgba(255, 255, 255, 0.1);
    --hairline: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.2);
    color-scheme: dark;
  }
}

:root[data-theme="light"] {
  --accent: #007AFF;
  --bg-canvas: #f2f2f7;
  --text-primary: #1c1c1e;
  --text-secondary: rgba(60, 60, 67, 0.6);
  --text-tertiary: rgba(60, 60, 67, 0.32);
  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-bg-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.65);
  --hairline: rgba(60, 60, 67, 0.13);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --accent: #0A84FF;
  --bg-canvas: #000000;
  --text-primary: #f2f2f7;
  --text-secondary: rgba(235, 235, 245, 0.6);
  --text-tertiary: rgba(235, 235, 245, 0.32);
  --glass-bg: rgba(28, 28, 30, 0.58);
  --glass-bg-strong: rgba(36, 36, 38, 0.78);
  --glass-border: rgba(255, 255, 255, 0.1);
  --hairline: rgba(255, 255, 255, 0.1);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background: var(--bg-canvas);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Soft blurred color field behind the glass, like Apple's Liquid Glass
   marketing surfaces — gives the backdrop-filter something to blur. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: var(--bg-canvas);
}
.backdrop .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
}
.backdrop .blob.b1 { width: 46vw; height: 46vw; top: -14vw; left: -10vw; background: #34C7FF; }
.backdrop .blob.b2 { width: 40vw; height: 40vw; top: 10vw; right: -14vw; background: #BF5AF2; opacity: 0.35; }
.backdrop .blob.b3 { width: 38vw; height: 38vw; bottom: -16vw; left: 20vw; background: #007AFF; opacity: 0.28; }
@media (prefers-color-scheme: dark) {
  .backdrop .blob { opacity: 0.22; }
}

.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; }

button { font: inherit; color: inherit; }

/* ---------------- Glass primitives ---------------- */

.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

.glass-strong {
  background: var(--glass-bg-strong);
  -webkit-backdrop-filter: blur(34px) saturate(190%);
  backdrop-filter: blur(34px) saturate(190%);
  border: 1px solid var(--glass-border);
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-pill);
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-prominent {
  background: var(--accent);
  color: #fff;
}
.btn-prominent:hover { opacity: 0.92; }

.btn-glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.btn-plain {
  background: transparent;
  color: var(--accent);
  padding: 8px 10px;
}

.btn-destructive { color: var(--red); background: transparent; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(120, 120, 128, 0.14);
  color: var(--text-secondary);
  border: none;
}
.btn-icon:hover { background: rgba(120, 120, 128, 0.22); }
.btn-icon.danger:hover { color: var(--red); }

input[type="text"], textarea {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--text-primary);
  background: rgba(120, 120, 128, 0.1);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
  resize: none;
}
input[type="text"]:focus, textarea:focus {
  border-color: var(--accent);
  background: rgba(120, 120, 128, 0.06);
}
input.mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; letter-spacing: 0.02em; }
::placeholder { color: var(--text-tertiary); }

.label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: block;
}

/* ---------------- App shell ---------------- */

#app { min-height: 100%; display: flex; flex-direction: column; }

.view { display: none; flex: 1; }
.view.active { display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  margin: 12px;
  border-radius: var(--radius-card);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(145deg, #34C7FF, #007AFF);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px;
}

.crumbs { display: flex; align-items: center; gap: 6px; font-size: 15px; color: var(--text-secondary); flex-wrap: wrap; }
.crumbs .crumb-link { color: var(--accent); cursor: pointer; font-weight: 600; }
.crumbs .crumb-current { color: var(--text-primary); font-weight: 700; }
.crumbs .sep { opacity: 0.5; }

.account { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(120,120,128,0.16);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
}
.account-menu-wrap { position: relative; }
.account-btn { display: flex; align-items: center; gap: 8px; background: transparent; border: none; cursor: pointer; padding: 4px; border-radius: 20px; }
.account-name { font-size: 14px; font-weight: 600; }
.account-dropdown {
  position: absolute;
  right: 0;
  top: 44px;
  min-width: 220px;
  padding: 8px;
  z-index: 30;
  display: none;
}
.account-dropdown.open { display: block; }
.account-dropdown .who { padding: 10px 12px; }
.account-dropdown .who .n { font-weight: 700; font-size: 14px; }
.account-dropdown .who .e { font-size: 12px; color: var(--text-secondary); }
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px;
  background: transparent; border: none; cursor: pointer; font-size: 14px;
}
.dropdown-item:hover { background: rgba(120,120,128,0.12); }
.dropdown-item.danger { color: var(--red); }
.dropdown-divider { height: 1px; background: var(--hairline); margin: 6px 4px; }

.content { flex: 1; padding: 4px 24px 48px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------------- Sign in ---------------- */

.signin-view { align-items: center; justify-content: center; }
.signin-card {
  width: min(380px, 92vw);
  padding: 40px 32px 32px;
  text-align: center;
  border-radius: var(--radius-alert);
}
.signin-mark {
  width: 64px; height: 64px; border-radius: 18px;
  margin: 0 auto 18px;
  background: linear-gradient(145deg, #34C7FF, #007AFF);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 30px; font-weight: 700;
  box-shadow: 0 10px 24px rgba(0,122,255,0.35);
}
.signin-title { font-size: 22px; font-weight: 700; margin: 0 0 6px; }
.signin-sub { font-size: 14px; color: var(--text-secondary); margin: 0 0 28px; line-height: 1.4; }
.apple-btn {
  width: 100%; background: #000; color: #fff; border-radius: 12px;
  padding: 13px; font-size: 16px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  .apple-btn { background: #fff; color: #000; }
}
.signin-foot { margin-top: 18px; font-size: 12px; color: var(--text-tertiary); }

.ck-auth-button {
  display: none;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  /* CloudKit renders its own "Sign in with Apple ID" button in here (likely
     an iframe) — we can't restyle its internals (font, exact padding,
     corner radius) from this page, but clipping + rounding the container
     at least keeps its corners visually consistent with the rest of the
     card. Give it a touch more height than the button itself needs so its
     text doesn't render cramped against the container edge. */
  overflow: hidden;
  border-radius: 14px;
}
.ck-auth-button.visible { display: flex; }
.ck-auth-button iframe { display: block; }

.demo-banner {
  margin-top: 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--orange);
  background: rgba(255, 149, 0, 0.12);
  border-radius: 10px;
  padding: 8px 12px;
  line-height: 1.4;
}

/* ---------------- Loading / error states ---------------- */

.loading-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 80px 20px; color: var(--text-secondary);
  grid-column: 1 / -1; width: 100%;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(120, 120, 128, 0.22);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state.is-error .icon { color: var(--orange); }
.empty-state .es-retry { margin-top: 6px; }

.manager-id-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 12px; font-size: 11.5px;
}
.manager-id-row .mid-label { color: var(--text-tertiary); }
.manager-id-row .mid-value {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  color: var(--text-secondary);
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------------- Section heading / search ---------------- */

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin: 20px 0 16px; flex-wrap: wrap;
}
.section-title { font-size: 28px; font-weight: 800; letter-spacing: -0.01em; margin: 0; }
.section-actions { display: flex; align-items: center; gap: 10px; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: var(--radius-pill);
  width: 240px; max-width: 60vw;
}
.search-box input { background: transparent; border: none; padding: 0; font-size: 14px; }
.search-box .icon { color: var(--text-tertiary); }

/* ---------------- Cards / grids ---------------- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }

.card {
  padding: 18px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 148px;
}
.card:hover { transform: translateY(-2px); }
.card .card-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: rgba(var(--accent-rgb), 0.14); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.card .card-title { font-size: 15px; font-weight: 700; line-height: 1.25; }
.card .card-sub { font-size: 12.5px; color: var(--text-secondary); line-height: 1.35; }
.card .card-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; }
.badge {
  font-size: 11.5px; font-weight: 700; color: var(--accent);
  background: rgba(var(--accent-rgb), 0.12);
  padding: 4px 9px; border-radius: var(--radius-pill);
}

.hunt-row {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; cursor: pointer; margin-bottom: 10px;
}
.hunt-row:hover { transform: translateY(-1px); }
.hunt-row .hr-icon {
  width: 44px; height: 44px; border-radius: 13px; flex: none;
  background: rgba(var(--accent-rgb), 0.14); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.hunt-row .hr-body { flex: 1; min-width: 0; }
.hunt-row .hr-title { font-size: 15.5px; font-weight: 700; }
.hunt-row .hr-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hunt-row .hr-meta { flex: none; display: flex; align-items: center; gap: 12px; }
.hunt-row .hr-count { font-size: 12.5px; color: var(--text-tertiary); }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 80px 20px; color: var(--text-secondary);
  gap: 8px;
}
.empty-state .icon { width: 44px; height: 44px; color: var(--text-tertiary); margin-bottom: 6px; }
.empty-state .es-title { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.empty-state .es-desc { font-size: 14px; max-width: 320px; line-height: 1.4; }

/* ---------------- Hunt editor ---------------- */

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .editor-grid { grid-template-columns: 1fr; }
  .preview-col { order: -1; }
}

.editor-col { display: flex; flex-direction: column; gap: 16px; }

.panel { padding: 20px; }
.panel + .panel { margin-top: 0; }
.panel-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); margin: 0 0 14px; display: flex; align-items: center; justify-content: space-between; }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
textarea.hunt-desc { min-height: 64px; }

.clue-list { display: flex; flex-direction: column; gap: 10px; }

.clue-row {
  border-radius: 16px;
  background: rgba(120, 120, 128, 0.07);
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.clue-row.dragging { opacity: 0.4; }
.clue-row.drag-over { border-color: var(--accent); }

.clue-summary {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px;
  cursor: pointer;
}
.clue-handle { cursor: grab; color: var(--text-tertiary); flex: none; touch-action: none; }
.clue-handle:active { cursor: grabbing; }
.clue-order {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.clue-summary-body { flex: 1; min-width: 0; }
.clue-summary-title { font-size: 14.5px; font-weight: 600; }
.clue-summary-body-text { font-size: 12.5px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.clue-tag-chip {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 11px; color: var(--text-secondary);
  background: rgba(120,120,128,0.14);
  padding: 3px 8px; border-radius: 6px; flex: none;
}
.clue-chevron { flex: none; color: var(--text-tertiary); transition: transform 0.2s ease; }
.clue-row.expanded .clue-chevron { transform: rotate(90deg); }

.clue-detail { display: none; padding: 0 16px 16px 46px; flex-direction: column; gap: 12px; }
.clue-row.expanded .clue-detail { display: flex; }

.clue-detail-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tag-generate-row { display: flex; gap: 8px; }
.tag-generate-row input { flex: 1; }

.add-clue-btn {
  width: 100%; justify-content: center;
  border: 1.5px dashed rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.06);
  color: var(--accent);
  border-radius: 16px;
  padding: 13px;
}
.add-clue-btn:hover { background: rgba(var(--accent-rgb), 0.1); }

.editor-footer {
  position: sticky; bottom: 16px;
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; margin-top: 6px;
  border-radius: var(--radius-card);
}

/* ---------------- Preview phone ---------------- */

.preview-col { position: sticky; top: 96px; }
.phone-frame {
  border-radius: 40px;
  padding: 14px;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  aspect-ratio: 9 / 18.5;
  display: flex; flex-direction: column;
  background: var(--glass-bg-strong);
}
.phone-notch { width: 90px; height: 20px; border-radius: 12px; background: rgba(120,120,128,0.25); margin: 0 auto 10px; }
.phone-title { text-align: center; font-size: 12.5px; font-weight: 700; color: var(--text-secondary); margin-bottom: 10px; }

.pv-progress { padding: 0 4px 10px; }
.pv-progress-label { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }
.pv-bars { display: flex; gap: 4px; }
.pv-bar { flex: 1; height: 6px; border-radius: 3px; background: rgba(120,120,128,0.25); }
.pv-bar.current { background: var(--accent); }
.pv-bar.done { background: rgba(var(--accent-rgb), 0.35); }

.pv-card {
  flex: 1;
  border-radius: 22px;
  display: flex; flex-direction: column;
  padding: 16px;
}
.pv-card-head { display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 700; color: var(--text-secondary); margin-bottom: 10px; }
.pv-card-body { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 15px; font-weight: 600; line-height: 1.35; padding: 6px; }
.pv-card-body.placeholder { color: var(--text-tertiary); font-weight: 500; font-size: 13px; }

.pv-footer-btn {
  margin-top: 10px; text-align: center; padding: 10px;
  border-radius: var(--radius-pill);
  background: var(--accent); color: #fff;
  font-size: 12.5px; font-weight: 700;
}

/* ---------------- Glass alert overlay ---------------- */

.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
.overlay.open { display: flex; }
.overlay-scrim {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.28);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.alert-card {
  position: relative;
  width: min(340px, 100%);
  padding: 30px 30px 24px;
  border-radius: var(--radius-alert);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  animation: pop-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
.alert-icon { width: 56px; height: 56px; }
.alert-icon.success { color: var(--green); }
.alert-icon.danger { color: var(--red); }
.alert-title { font-size: 19px; font-weight: 700; margin: 4px 0 0; }
.alert-msg { font-size: 14.5px; color: var(--text-secondary); line-height: 1.4; margin: 0; }
.alert-actions { display: flex; gap: 10px; margin-top: 14px; width: 100%; }
.alert-actions .btn { flex: 1; justify-content: center; }
.alert-tap-hint { font-size: 12px; color: var(--text-tertiary); margin-top: 8px; }

/* ---------------- Toast ---------------- */

.toast {
  position: fixed; left: 50%; bottom: 30px; z-index: 110;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.2,0.9,0.3,1.2), opacity 0.28s ease;
  padding: 12px 20px; border-radius: var(--radius-pill);
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .icon { color: var(--green); }

/* ---------------- Responsive ---------------- */

@media (max-width: 620px) {
  .content { padding: 4px 14px 40px; }
  .topbar { padding: 12px 16px; }
  .section-title { font-size: 24px; }
}
