/* ============ Level · Style ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-1: #0a0908;
  --bg-2: #1a1410;
  --bg-3: #2a1f15;
  --accent: #f59e0b;
  --accent-2: #fbbf24;
  --accent-3: #fcd34d;
  --green:  #10b981;
  --red:    #ef4444;
  --text:   #fef3c7;
  --muted:  rgba(254,243,199,.55);
  --faint:  rgba(254,243,199,.30);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}

html, body {
  background: var(--bg-1);
  color: var(--text);
  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding-top: calc(58px + var(--safe-top));
  padding-bottom: calc(28px + var(--safe-bot));
}

/* Ambient warm background */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  background: var(--bg-1);
}
.ambient-bg::before {
  content: '';
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(50% 50% at 25% 30%, rgba(245,158,11,.15), transparent 60%),
    radial-gradient(50% 50% at 75% 70%, rgba(217,119,6,.12), transparent 60%);
  filter: blur(40px);
  animation: bg-warm 18s ease-in-out infinite;
}
@keyframes bg-warm {
  0%, 100% { transform: translate(0,0); }
  50% { transform: translate(-2%, 2%); }
}
.ambient-bg .grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(245,158,11,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245,158,11,.04) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 40%, transparent 90%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 40%, transparent 90%);
}

/* TOP BAR */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(58px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10,9,8,.78);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid rgba(245,158,11,.10);
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  border-radius: 8px;
  position: relative;
  box-shadow: 0 6px 18px rgba(245,158,11,.5);
}
.brand .mark::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 8px;
  border: 2px solid rgba(0,0,0,.2);
  border-top-color: rgba(255,255,255,.3);
}
.brand .mark::after {
  content: '';
  position: absolute;
  width: 8px; height: 8px;
  background: rgba(255,255,255,.85);
  border-radius: 50%;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px rgba(255,255,255,.5);
}
.brand-name {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.brand span:not(.mark) {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(245,158,11,.18);
  background: rgba(245,158,11,.05);
  color: var(--text);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 16px;
  transition: background .2s, transform .15s;
}
.icon-btn:hover { background: rgba(245,158,11,.12); }
.icon-btn:active { transform: scale(.92); }
.install-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-1);
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(245,158,11,.4);
}
.hidden { display: none !important; }

main { padding: 18px; max-width: 480px; margin: 0 auto; }

.panel { animation: fade .35s cubic-bezier(.2,.9,.3,1.05); }
@keyframes fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Permission / Desktop messages */
.perm-panel, .desktop-panel {
  text-align: center;
  padding: 60px 22px;
  margin-top: 30px;
}
.perm-icon {
  font-size: 56px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 20px rgba(245,158,11,.4));
}
.perm-panel h2, .desktop-panel h2 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.perm-panel p, .desktop-panel p {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
  line-height: 1.7;
}
.url-box {
  background: rgba(245,158,11,.08);
  border: 1px solid rgba(245,158,11,.25);
  border-radius: 12px;
  padding: 14px 18px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  direction: ltr;
  letter-spacing: 0;
  color: var(--accent-2);
}

/* ============ LEVEL STAGE ============ */
.level-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 18px auto 28px;
  position: relative;
}
.bubble-container {
  width: 320px; height: 320px;
  max-width: 84vw;
  max-height: 84vw;
  position: relative;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, rgba(245,158,11,.12), transparent 50%),
    radial-gradient(circle, rgba(20,15,10,.7), rgba(10,9,8,.95) 90%);
  border: 1px solid rgba(245,158,11,.22);
  box-shadow:
    inset 0 -16px 40px rgba(0,0,0,.6),
    inset 0 8px 30px rgba(245,158,11,.08),
    0 30px 70px rgba(245,158,11,.20),
    0 0 0 6px rgba(245,158,11,.04);
  overflow: hidden;
  cursor: default;
}
.grid-rings {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* The bubble itself */
.bubble {
  position: absolute;
  width: 60px; height: 60px;
  top: 50%; left: 50%;
  margin-top: -30px;
  margin-left: -30px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.85), rgba(252,211,77,.55) 50%, rgba(245,158,11,.4) 100%);
  box-shadow:
    inset 0 -8px 16px rgba(217,119,6,.5),
    inset 0 4px 10px rgba(255,255,255,.5),
    0 0 30px rgba(252,211,77,.6),
    0 0 60px rgba(245,158,11,.4);
  transition: transform .15s cubic-bezier(.34,1.56,.64,1), background .25s, box-shadow .25s;
  will-change: transform;
}
.bubble.level {
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.85), rgba(110,231,183,.7) 50%, rgba(16,185,129,.5) 100%);
  box-shadow:
    inset 0 -8px 16px rgba(6,95,70,.5),
    inset 0 4px 10px rgba(255,255,255,.5),
    0 0 40px rgba(16,185,129,.6),
    0 0 80px rgba(16,185,129,.4);
}
.bubble.locked {
  border: 2px dashed rgba(255,255,255,.5);
}

.level-status {
  position: absolute;
  top: 18px; left: 0; right: 0;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 3px;
  text-transform: uppercase;
}
.level-status.green { color: var(--green); }
.level-status.red { color: var(--red); }

/* ============ READOUTS ============ */
.readouts {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 8px;
  margin-bottom: 22px;
}
.readout {
  text-align: center;
  padding: 14px 8px;
  background: rgba(245,158,11,.04);
  border: 1px solid rgba(245,158,11,.10);
  border-radius: 14px;
}
.readout.main {
  background: rgba(245,158,11,.10);
  border-color: rgba(245,158,11,.30);
}
.readout .label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--faint);
  margin-bottom: 6px;
}
.readout .value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.readout.main .value {
  font-size: 36px;
  color: var(--accent-2);
}
.readout .value.ok { color: var(--green); }
.readout .value.bad { color: var(--red); }

/* Reference angles */
.reference-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 22px;
}
.ref-chip {
  padding: 10px 4px;
  background: rgba(245,158,11,.04);
  border: 1px solid rgba(245,158,11,.10);
  border-radius: 12px;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  transition: all .25s;
}
.ref-chip span:first-child { display: block; margin-bottom: 2px; }
.ref-chip .num {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.ref-chip.match {
  background: rgba(16,185,129,.15);
  border-color: rgba(16,185,129,.5);
  color: var(--green);
  box-shadow: 0 4px 12px rgba(16,185,129,.25);
}
.ref-chip.match .num { color: var(--green); }

/* Action buttons */
.actions-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
}
.btn-primary {
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-1);
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 12px 26px -8px rgba(245,158,11,.55);
  transition: transform .15s;
}
.btn-primary:active { transform: scale(.97); }
.btn-secondary {
  padding: 14px;
  background: rgba(245,158,11,.06);
  border: 1px solid rgba(245,158,11,.18);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  border-radius: 14px;
  cursor: pointer;
  transition: background .2s;
}
.btn-secondary:hover { background: rgba(245,158,11,.12); }

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0;
  background: rgba(10,9,8,.78);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: grid;
  place-items: end center;
  animation: modal-in .25s ease;
}
@keyframes modal-in { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: rgba(26,20,16,.94);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(245,158,11,.18);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 24px 22px calc(28px + var(--safe-bot));
  width: 100%;
  max-width: 480px;
  animation: sheet-up .35s cubic-bezier(.2,.9,.3,1.05);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-card .handle {
  width: 38px; height: 4px;
  background: rgba(245,158,11,.30);
  border-radius: 2px;
  margin: -8px auto 16px;
}
.modal-card h3 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.modal-card p {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 18px;
  line-height: 1.6;
}
.modal-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid rgba(245,158,11,.18);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  margin-bottom: 14px;
}
.modal-input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-summary {
  background: rgba(245,158,11,.06);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  text-align: center;
}
.modal-summary .stat-mini { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.modal-summary .stat-mini .k {
  display: block;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--faint);
  font-family: 'IBM Plex Mono', monospace;
  margin-top: 4px;
  font-weight: 500;
}
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modal-card .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid rgba(245,158,11,.08);
}
.modal-card .row:last-child { border-bottom: 0; }

/* History list */
.history-list { max-height: 50vh; overflow-y: auto; }
.history-item {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: rgba(245,158,11,.04);
  border: 1px solid rgba(245,158,11,.10);
  border-radius: 12px;
  margin-bottom: 8px;
}
.history-item .angle-circle {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: rgba(245,158,11,.15);
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}
.history-item .info .name { font-weight: 600; font-size: 14px; }
.history-item .info .when { font-size: 11px; color: var(--muted); margin-top: 2px; font-family: 'IBM Plex Mono', monospace; }
.history-item .del-btn {
  background: transparent;
  border: 1px solid rgba(245,158,11,.18);
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.history-item .del-btn:hover { background: rgba(239,68,68,.10); color: var(--red); border-color: rgba(239,68,68,.4); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .ico { font-size: 40px; margin-bottom: 12px; opacity: .5; }

/* Toast */
.toast {
  position: fixed;
  top: calc(70px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26,20,16,.96);
  border: 1px solid rgba(245,158,11,.30);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 18px 40px rgba(0,0,0,.6);
  backdrop-filter: blur(10px);
  animation: toast-in .25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.toast.success { color: var(--green); border-color: rgba(16,185,129,.5); }
.toast.error { color: var(--red); border-color: rgba(239,68,68,.5); }
