:root {
  color-scheme: dark;
  --bg: #060407;
  --bg-2: #0b0710;
  --ink: #110910;
  --crypt: rgba(24, 13, 20, 0.82);
  --crypt-2: rgba(42, 20, 27, 0.78);
  --glass: rgba(20, 12, 18, 0.72);
  --glass-strong: rgba(44, 23, 31, 0.9);
  --border: rgba(232, 215, 187, 0.15);
  --border-hot: rgba(255, 55, 87, 0.42);
  --text: #f5eadb;
  --muted: #a99487;
  --soft: #d9c7b2;
  --bone: #fff1da;
  --green: #99f7bf;
  --green-dark: #103d2a;
  --red: #d42036;
  --red-bright: #ff4660;
  --red-dark: #4d0710;
  --gold: #d5a954;
  --gold-soft: #f4d28c;
  --violet: #7b3559;
  --shadow: rgba(0, 0, 0, 0.58);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --phone-max: 430px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { min-height: 100%; background: var(--bg); width: 100%; max-width: 100%; overflow-x: hidden; }
html, body { margin: 0; width: 100%; max-width: 100%; overflow-x: hidden; }
body {
  min-height: 100dvh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -12%, rgba(255, 60, 91, .32), transparent 34%),
    radial-gradient(circle at 10% 14%, rgba(213, 169, 84, .15), transparent 28%),
    radial-gradient(circle at 88% 10%, rgba(123, 53, 89, .20), transparent 32%),
    linear-gradient(180deg, #09060a 0%, #050304 62%, #020102 100%);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .72;
  background:
    linear-gradient(115deg, transparent 0 47%, rgba(213, 169, 84, .055) 48%, transparent 52%),
    radial-gradient(circle at 50% 34%, transparent 0 136px, rgba(213,169,84,.10) 137px 138px, transparent 140px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.018) 0 1px, transparent 1px 32px);
  mask-image: linear-gradient(180deg, #000 0%, rgba(0,0,0,.86) 48%, transparent 100%);
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.035), transparent 16%, rgba(0,0,0,.28));
  mix-blend-mode: overlay;
}
button, input { font: inherit; }
button { cursor: pointer; border: 0; color: inherit; touch-action: manipulation; }
button:active { transform: translateY(1px) scale(.99); }

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 14px calc(116px + var(--safe-bottom));
  position: relative;
}
.app-shell::before,
.app-shell::after {
  content: "☩";
  position: fixed;
  top: 42%;
  color: rgba(213, 169, 84, .07);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(96px, 33vw, 156px);
  z-index: -1;
  filter: blur(.25px);
}
.app-shell::before { left: max(4px, calc(50% - 320px)); transform: rotate(-12deg); }
.app-shell::after { right: max(4px, calc(50% - 320px)); transform: rotate(12deg); }

.topbar, .sheet-header, .settings-header, .section-heading, .streak-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.topbar {
  min-height: 54px;
  padding: 2px 2px 0;
}
.topbar > div,
.sheet-header > div,
.settings-header > div {
  min-width: 0;
}
h1, h2, p { margin: 0; }
h1, h2 {
  font-family: Georgia, "Times New Roman", serif;
  text-transform: uppercase;
  color: var(--bone);
  text-shadow: 0 0 18px rgba(255,70,96,.22);
  overflow-wrap: anywhere;
}
h1 { font-size: clamp(22px, 6vw, 28px); letter-spacing: .075em; font-weight: 900; line-height: .95; }
h2 { font-size: 18px; letter-spacing: .055em; font-weight: 900; line-height: 1.05; }
.eyebrow {
  color: var(--gold);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: .22em;
  font-weight: 900;
  margin-bottom: 6px;
}

.icon-button {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 17px 17px 22px 22px;
  background: linear-gradient(180deg, rgba(94,43,55,.86), rgba(17,8,12,.94));
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 12px 30px rgba(0,0,0,.32);
  display: grid;
  place-items: center;
  font-size: 22px;
  color: var(--bone);
}

.score-card {
  margin-top: 18px;
  min-height: clamp(322px, 41dvh, 392px);
  border-radius: 30px 30px 40px 40px;
  background:
    linear-gradient(180deg, rgba(96, 43, 55, .36), rgba(9, 5, 8, .92)),
    radial-gradient(circle at 50% 38%, rgba(255,70,96,.18), transparent 43%),
    linear-gradient(135deg, rgba(255,255,255,.06), transparent 32%);
  border: 1px solid var(--border);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.035),
    inset 0 -38px 70px rgba(0,0,0,.52),
    0 26px 78px rgba(0,0,0,.52),
    0 0 42px rgba(129, 18, 34, .16);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  padding: 34px 22px 26px;
  isolation: isolate;
}
.score-card::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(213,169,84,.18);
  border-radius: 23px 23px 34px 34px;
  pointer-events: none;
  z-index: 2;
}
.score-card::after {
  content: "✦  ☩  ✦";
  position: absolute;
  bottom: 13px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(213,169,84,.42);
  letter-spacing: .6em;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 11px;
  white-space: nowrap;
  z-index: 2;
}
.gothic-frame {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  color: rgba(245,234,219,.54);
  font-size: 19px;
  text-shadow: 0 0 16px rgba(255,70,96,.36);
  z-index: 2;
}
.gothic-frame span:nth-child(2) { font-size: 25px; transform: rotate(45deg); }
.score-orbit {
  position: absolute;
  width: min(62vw, 244px);
  height: min(62vw, 244px);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(153,247,191,.18), transparent 56%),
    conic-gradient(from 0deg, transparent, rgba(213,169,84,.18), transparent, rgba(153,247,191,.14), transparent);
  filter: blur(.8px);
  transition: .35s ease;
  animation: rotateSigil 18s linear infinite;
  z-index: 0;
}
.score-card.negative .score-orbit { background: radial-gradient(circle, rgba(255,70,96,.24), transparent 56%), conic-gradient(from 0deg, transparent, rgba(255,70,96,.28), transparent); }
.score-card.neutral .score-orbit { background: radial-gradient(circle, rgba(213,169,84,.14), transparent 58%), conic-gradient(from 0deg, transparent, rgba(213,169,84,.16), transparent); }
.score-label {
  color: var(--gold-soft);
  font-size: 11px;
  font-weight: 950;
  z-index: 1;
  text-transform: uppercase;
  letter-spacing: .18em;
}
.karma-score {
  z-index: 1;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(84px, 26vw, 132px);
  line-height: .82;
  letter-spacing: -6px;
  font-weight: 950;
  margin: 16px 0 14px;
  color: var(--bone);
  text-shadow: 0 0 26px rgba(153,247,191,.24), 0 5px 0 rgba(0,0,0,.68);
  transition: color .25s ease, text-shadow .25s ease, transform .2s ease;
  font-variant-numeric: tabular-nums;
}
.score-card.positive .karma-score { color: var(--green); text-shadow: 0 0 32px rgba(153,247,191,.42), 0 5px 0 rgba(0,0,0,.65); }
.score-card.negative .karma-score { color: var(--red-bright); text-shadow: 0 0 34px rgba(255,70,96,.50), 0 5px 0 rgba(0,0,0,.70); }
.score-card.neutral .karma-score { color: var(--bone); text-shadow: 0 0 26px rgba(213,169,84,.24), 0 5px 0 rgba(0,0,0,.70); }
.karma-score.pop { animation: pop .34s cubic-bezier(.2, 1.4, .4, 1); }
.score-card.shake { animation: shake .34s ease; }
.karma-mood {
  z-index: 1;
  color: var(--soft);
  line-height: 1.42;
  max-width: 320px;
  font-size: 14.5px;
  text-wrap: balance;
}
.streak-row {
  z-index: 1;
  margin-top: 20px;
  width: 100%;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
}
.streak-row span {
  min-width: 0;
  max-width: 50%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.insight-card, .history-card {
  margin-top: 14px;
  padding: 17px;
  border-radius: 23px 23px 29px 29px;
  background: linear-gradient(180deg, rgba(31,17,24,.86), rgba(8,5,7,.88));
  border: 1px solid var(--border);
  box-shadow: inset 0 0 22px rgba(0,0,0,.36), 0 14px 45px rgba(0,0,0,.22);
  position: relative;
  overflow: hidden;
}
.insight-card::before, .history-card::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(213,169,84,.08);
  border-radius: inherit;
  pointer-events: none;
}
.insight-title { color: var(--gold); font-size: 12.5px; font-weight: 950; margin-bottom: 7px; text-transform: uppercase; letter-spacing: .08em; }
.insight-card p:last-child { color: var(--soft); line-height: 1.47; font-size: 13.5px; }
.ghost-button {
  min-height: 38px;
  border: 1px solid var(--border);
  background: rgba(77,7,16,.34);
  border-radius: 999px;
  padding: 8px 13px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 800;
}
.history-list { list-style: none; padding: 0; margin: 15px 0 0; display: grid; gap: 9px; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  min-height: 62px;
  border-radius: 17px 17px 21px 21px;
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(213,169,84,.12);
}
.history-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.history-icon { flex: 0 0 auto; font-size: 22px; filter: drop-shadow(0 0 8px rgba(255,70,96,.20)); }
.history-title { font-weight: 850; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-time { color: var(--muted); font-size: 12px; margin-top: 2px; }
.history-value { font-weight: 950; font-size: 18px; font-variant-numeric: tabular-nums; }
.history-value.good { color: var(--green); }
.history-value.bad { color: var(--red-bright); }
.empty-state { color: var(--muted); text-align: center; padding: 18px 0; line-height: 1.45; }

.action-dock {
  position: fixed;
  left: 50%;
  bottom: max(10px, var(--safe-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 22px), 456px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  z-index: 20;
  padding: 9px;
  border-radius: 27px;
  border: 1px solid rgba(213,169,84,.22);
  background: rgba(6,4,7,.72);
  backdrop-filter: blur(24px) saturate(1.2);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  box-shadow: 0 18px 48px rgba(0,0,0,.62), inset 0 0 18px rgba(213,169,84,.05);
}
.action-button {
  min-height: 76px;
  border-radius: 21px 21px 25px 25px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .105em;
  font-weight: 950;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10);
}
.action-button::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: inherit;
  pointer-events: none;
}
.action-button::after {
  content: "";
  position: absolute;
  inset: -40% -10%;
  background: linear-gradient(115deg, transparent 35%, rgba(255,255,255,.11), transparent 64%);
  transform: translateX(-70%);
  transition: transform .35s ease;
}
.action-button:active::after { transform: translateX(70%); }
.action-button span { font-size: 25px; z-index: 1; }
.action-button strong { z-index: 1; }
.action-button.positive { background: linear-gradient(180deg, rgba(33,126,78,.68), rgba(8,32,22,.94)); border: 1px solid rgba(153,247,191,.28); color: #e0ffe9; }
.action-button.negative { background: linear-gradient(180deg, rgba(155,23,38,.78), rgba(45,4,10,.96)); border: 1px solid rgba(255,70,96,.35); color: #ffe1e5; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.66);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 30;
}
.bottom-sheet {
  position: fixed;
  z-index: 40;
  left: 0;
  right: 0;
  bottom: 0;
  transform: translateX(0);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  max-height: min(82dvh, 720px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 10px 14px calc(18px + var(--safe-bottom));
  border-radius: 31px 31px 0 0;
  background: linear-gradient(180deg, rgba(33,16,22,.98), rgba(6,3,5,.99));
  border: 1px solid var(--border);
  box-shadow: 0 -28px 70px rgba(0,0,0,.58);
  animation: slideUp .22s ease;
}
.sheet-handle {
  width: 52px;
  height: 5px;
  background: linear-gradient(90deg, transparent, rgba(213,169,84,.72), transparent);
  border-radius: 999px;
  margin: 0 auto 14px;
}
.habit-list, .configured-list { display: grid; gap: 10px; margin-top: 18px; min-width: 0; }
.habit-row {
  width: 100%;
  max-width: 100%;
  text-align: left;
  padding: 13px;
  min-height: 68px;
  border-radius: 19px 19px 24px 24px;
  border: 1px solid rgba(213,169,84,.15);
  background: linear-gradient(180deg, rgba(255,255,255,.046), rgba(0,0,0,.12));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}
.habit-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.habit-info > div { min-width: 0; }
.habit-icon {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 16px 16px 20px 20px;
  background: radial-gradient(circle at 50% 20%, rgba(213,169,84,.20), rgba(77,7,16,.24));
  border: 1px solid rgba(213,169,84,.16);
  display: grid;
  place-items: center;
  font-size: 23px;
}
.habit-title { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-type { color: var(--muted); font-size: 12px; margin-top: 3px; }
.habit-value { flex: 0 0 auto; font-weight: 950; font-size: 22px; font-variant-numeric: tabular-nums; }
.habit-value.good { color: var(--green); }
.habit-value.bad { color: var(--red-bright); }

.configured-list .habit-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}
.configured-list .habit-info {
  min-width: 0;
  overflow: hidden;
}
.configured-list .delete-button {
  grid-column: 1 / -1;
  justify-self: end;
  max-width: 100%;
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 14px calc(24px + var(--safe-bottom));
  overflow: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 50% 0%, rgba(155,23,38,.26), transparent 36%),
    linear-gradient(180deg, var(--bg-2), #020101);
  animation: fadeIn .18s ease;
}
.settings-panel * {
  max-width: 100%;
}
.habit-form {
  margin-top: 22px;
  display: grid;
  gap: 12px;
  padding: 15px;
  border-radius: 23px 23px 29px 29px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(31,17,24,.86), rgba(8,5,7,.90));
  box-shadow: inset 0 0 28px rgba(0,0,0,.40);
}
label { display: grid; gap: 7px; color: var(--gold); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 900; }
input {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(213,169,84,.18);
  background: rgba(0,0,0,.30);
  color: var(--text);
  border-radius: 15px;
  padding: 13px 14px;
  outline: none;
  font-size: 16px;
}
input:focus { border-color: rgba(255,70,96,.68); box-shadow: 0 0 0 4px rgba(255,70,96,.14); }
.primary-button {
  min-height: 54px;
  border-radius: 17px 17px 23px 23px;
  background: linear-gradient(180deg, #9b1726, #4d0710);
  border: 1px solid rgba(255,70,96,.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 14px 30px rgba(77,7,16,.32);
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.delete-button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 9px 11px;
  border-radius: 13px;
  background: rgba(77,7,16,.56);
  color: #ffc5cc;
  border: 1px solid rgba(255,70,96,.18);
  font-weight: 800;
}
.danger-link {
  margin: 22px 0;
  width: 100%;
  min-height: 44px;
  background: transparent;
  color: #ff9aa4;
  text-decoration: underline;
}
.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(106px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 34px), 420px);
  padding: 14px 16px;
  border-radius: 19px 19px 24px 24px;
  background: rgba(17,10,15,.95);
  border: 1px solid var(--border);
  text-align: center;
  box-shadow: 0 16px 50px rgba(0,0,0,.42), 0 0 28px rgba(255,70,96,.14);
  font-weight: 800;
}
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 55; overflow: hidden; }
.confetti {
  position: absolute;
  top: -16px;
  width: 8px;
  height: 14px;
  border-radius: 0 0 5px 5px;
  animation: confettiFall 900ms ease-in forwards;
  box-shadow: 0 0 10px currentColor;
}
[hidden] { display: none !important; }

@keyframes pop { 0% { transform: scale(.92); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes confettiFall { to { transform: translateY(105vh) rotate(540deg); opacity: 0; } }
@keyframes rotateSigil { to { transform: rotate(360deg); } }

@media (min-width: 430px) {
  .app-shell { padding-inline: 18px; }
  .score-card { margin-top: 20px; }
}

@media (max-height: 760px) {
  .score-card { min-height: 298px; padding-block: 30px 24px; }
  .karma-score { font-size: clamp(76px, 23vw, 112px); margin-block: 12px; }
  .karma-mood { font-size: 13.5px; }
  .insight-card { display: none; }
  .action-button { min-height: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
