/* Brand tokens (warm cream, terracotta primary, Notion-style ink, system sans) */
:root {
  --background: hsl(40 14% 95%);
  --foreground: hsl(45 8% 20%);
  --card: hsl(0 0% 100%);
  --primary: hsl(14 64% 64%);
  --primary-soft: hsl(14 64% 64% / .16);
  --primary-foreground: hsl(45 8% 20%);
  --accent: hsl(207 58% 57%);
  --destructive: hsl(0 84% 60%);
  --destructive-ink: hsl(0 70% 40%);
  --border: hsl(40 8% 88%);
  --muted-foreground: hsl(45 5% 40%);
  --radius: .625rem;
  --surface-shadow: 0 1px 2px hsl(45 8% 20% / .05), 0 1px 3px hsl(45 8% 20% / .04);
  --surface-shadow-hover: 0 2px 6px hsl(45 8% 20% / .08), 0 4px 14px hsl(45 8% 20% / .06);
  --ease: cubic-bezier(.25, .1, .25, 1);
  --gutter: clamp(16px, 4vw, 48px);
  --side: 248px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--background); color: var(--foreground);
  font: 16px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shared pieces ---------- */
.muted { color: var(--muted-foreground); }
.btn { border: 1px solid var(--primary); border-radius: var(--radius); padding: 0 18px; min-height: 46px; font-weight: 600;
  background: var(--primary); color: var(--primary-foreground); box-shadow: var(--surface-shadow);
  transition: box-shadow .15s var(--ease), transform .15s var(--ease), background .15s var(--ease); }
.btn:hover { box-shadow: var(--surface-shadow-hover); }
.btn:active { transform: translateY(1px); }
.btn.alt { background: var(--card); border-color: var(--border); }
.btn.danger { background: transparent; border-color: var(--border); color: var(--destructive-ink); box-shadow: none; }
.btn.danger:hover { border-color: var(--destructive); }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--foreground); font-weight: 600; padding: 8px 12px; border-radius: 8px; line-height: 1.3; white-space: nowrap; }
.link:hover { background: var(--primary-soft); }
.field { width: 100%; min-height: 46px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--surface-shadow); }
.field::placeholder { color: var(--muted-foreground); }
textarea.field { min-height: 120px; resize: vertical; }
select.field { appearance: none; -webkit-appearance: none; padding-right: 44px; cursor: pointer; text-overflow: ellipsis;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2366635c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 16px center / 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--surface-shadow); }
button.card { text-align: left; width: 100%; transition: box-shadow .15s var(--ease), border-color .15s var(--ease); }
button.card:hover { box-shadow: var(--surface-shadow-hover); border-color: hsl(40 8% 80%); }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-foreground); margin: 28px 0 10px; }
.empty .btn { margin-top: 16px; min-width: 120px; }
.empty { text-align: center; color: var(--muted-foreground); padding: 56px 16px; border: 1px dashed var(--border); border-radius: var(--radius); }
.score { flex: none; min-width: 64px; text-align: center; font-weight: 700; background: var(--primary-soft); border-radius: 8px; padding: 6px 10px; }
.score small { font-weight: 500; color: var(--muted-foreground); }
.save-ind { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--muted-foreground); white-space: nowrap; }
.save-ind[data-state=""] { visibility: hidden; }
.save-ind i { width: 14px; height: 14px; flex: none; border-radius: 50%; display: grid; place-items: center; }
.save-ind[data-state="saving"] i { border: 2px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.save-ind[data-state="saved"] i { background: hsl(142 40% 38%); }
.save-ind[data-state="saved"] i::after { content: ""; width: 3px; height: 6px; border: solid #fff; border-width: 0 1.5px 1.5px 0; transform: translateY(-.5px) rotate(45deg); }
.save-ind[data-state="error"], .save-ind[data-state="offline"] { color: var(--destructive-ink); }
.save-ind[data-state="error"] i, .save-ind[data-state="offline"] i { background: var(--destructive); }
@keyframes spin { to { transform: rotate(360deg); } }
.edit-btn { flex: none; min-height: 30px; padding: 2px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--card);
  font-size: 13px; font-weight: 600; line-height: 1.3; color: var(--foreground); transition: background .15s var(--ease), border-color .15s var(--ease); }
.edit-btn:hover { background: var(--primary-soft); border-color: var(--primary); }
.msg { padding: 12px 14px; border-radius: var(--radius); background: var(--primary-soft); font-size: 14px; }
.msg.err { background: transparent; border: 1px solid var(--destructive); color: var(--destructive-ink); }

/* brand lockup */
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.brand b { display: block; font-size: 20px; line-height: 1.1; letter-spacing: .02em; }
.brand span { display: block; font-size: 12px; line-height: 1.3; color: var(--muted-foreground); }

/* ---------- app frame ---------- */
#app { min-height: 100dvh; }
.frame { min-height: 100dvh; display: grid; grid-template-columns: 1fr; }
.side { display: none; }
.content { min-width: 0; display: flex; flex-direction: column; }
header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px; background: var(--background); border-bottom: 1px solid var(--border); }
header h1 { flex: 1; font-size: 20px; line-height: 1.2; }
.hdr-acct { display: flex; align-items: center; gap: 4px; }
.hdr-brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.hdr-brand img { width: 32px; height: 32px; border-radius: 8px; }
main { flex: 1; padding: 20px var(--gutter) calc(env(safe-area-inset-bottom) + 104px); }
.page-desc { color: var(--muted-foreground); font-size: 15px; max-width: 70ch; margin-bottom: 18px; }

nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.is-edit nav.bottom { display: none; }
.is-edit main { padding-bottom: 40px; }
nav button { background: none; border: 0; color: var(--muted-foreground); font-weight: 600; font-size: 13px; min-height: 58px; padding: 8px 4px; }
nav.bottom button[aria-current="page"] { color: var(--foreground); box-shadow: inset 0 2px 0 var(--primary); }
nav button .ico { display: block; font-size: 20px; line-height: 1.2; }

/* ---------- programs ---------- */
.add { display: flex; gap: 10px; margin-bottom: 18px; max-width: 640px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.prog { display: flex; align-items: center; gap: 12px; padding: 16px; }
.prog .name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.prog .meta { display: block; font-weight: 400; font-size: 13px; color: var(--muted-foreground); }

/* ---------- score editor ---------- */
.edit { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "name" "total" "doms" "notes" "actions"; align-items: start; }
.edit .a-name { grid-area: name; } .edit .a-total { grid-area: total; } .edit .doms { grid-area: doms; }
.edit .a-notes { grid-area: notes; } .edit .a-actions { grid-area: actions; }
.total { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; position: sticky; top: calc(env(safe-area-inset-top) + 58px); z-index: 4; }
.total b { font-size: 28px; line-height: 1.1; }
.total small { display: block; color: var(--muted-foreground); font-size: 13px; }
.doms { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.dom { padding: 14px 16px; }
.dom .label { font-weight: 600; }
.dom .opt { font-size: 12px; color: var(--muted-foreground); margin-left: 8px; font-weight: 500; }
.dom .hint { font-size: 13px; color: var(--muted-foreground); margin: 2px 0 12px; }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seg button { height: 46px; border: 1px solid var(--border); border-radius: 8px; background: var(--background); font-weight: 600; font-size: 17px;
  transition: background .12s var(--ease), border-color .12s var(--ease); }
.seg button:hover { border-color: var(--primary); }
.seg button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.dom-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.dom-head .link { padding: 2px 8px; font-size: 13px; color: var(--destructive-ink); margin: -2px -8px 0 0; }
.add-dom { min-height: 96px; border: 2px dashed var(--border); border-radius: var(--radius); background: transparent; color: var(--muted-foreground);
  font-weight: 600; transition: border-color .15s var(--ease), color .15s var(--ease), background .15s var(--ease); }
.add-dom:hover { border-color: var(--primary); color: var(--foreground); background: var(--primary-soft); }
.add-dom-form { border: 2px dashed var(--primary); box-shadow: none; scroll-margin-top: calc(env(safe-area-inset-top) + 150px); }
/* Extra room below the form so it can scroll to the top of the screen with the keyboard open. */
.is-edit.adding main { padding-bottom: 80dvh; }
.add-dom-form .hint { margin: 0; }
.name-field { font-weight: 600; font-size: 18px; }

/* ---------- compare ---------- */
.pick { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: center; max-width: 900px; }
.cmp-wrap { margin-top: 18px; max-width: 900px; overflow-x: auto; }
.cmp { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cmp th, .cmp td { padding: 12px 14px; text-align: center; border-bottom: 1px solid var(--border); }
.cmp th:first-child, .cmp td:first-child { text-align: left; color: var(--muted-foreground); font-weight: 500; }
.cmp th { overflow-wrap: anywhere; }
.cmp th .th-name { display: block; margin-bottom: 8px; }
.cmp td.w { font-weight: 800; background: var(--primary-soft); }
.cmp tfoot td { font-weight: 800; font-size: 18px; border-bottom: 0; }
.verdict { position: relative; overflow: hidden; margin-top: 16px; padding: 20px; max-width: 900px; display: grid; gap: 16px 20px;
  grid-template-columns: auto minmax(0, 1fr); align-items: center; border-color: hsl(14 64% 64% / .55); background: hsl(14 64% 64% / .1);
  animation: pop .45s var(--ease) both; }
.verdict::before { content: "✨"; position: absolute; top: 10px; right: 16px; font-size: 18px; opacity: .85; animation: twinkle 2.4s ease-in-out infinite; }
.verdict::after { content: "✦"; position: absolute; top: 16px; right: 46px; font-size: 14px; color: var(--primary); opacity: .7; animation: twinkle 2.4s ease-in-out .8s infinite; }
.v-badge { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; background: var(--card);
  box-shadow: 0 0 0 4px hsl(14 64% 64% / .25), var(--surface-shadow); animation: bounce 1.8s ease-in-out infinite; }
.v-eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-foreground); }
.v-title { font-size: 18px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; margin: 2px 0 8px; }
.v-chip { display: inline-block; padding: 3px 12px; border-radius: 999px; background: var(--primary); color: var(--primary-foreground); font-size: 13px; font-weight: 700; }
.v-bars { grid-column: 1 / -1; display: grid; gap: 10px; }
.v-row { display: grid; grid-template-columns: minmax(70px, 140px) minmax(0, 1fr) 48px; gap: 12px; align-items: center; font-size: 14px; }
.v-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.v-track { height: 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); overflow: hidden; }
.v-fill { display: block; height: 100%; border-radius: 999px; background: hsl(40 8% 74%); transform-origin: left; animation: grow .7s var(--ease) both; }
.v-row.lead .v-fill, .is-tie .v-fill { background: var(--primary); }
.v-val { text-align: right; font-weight: 700; }
.v-row.lead .v-val { color: var(--foreground); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes twinkle { 0%, 100% { opacity: .35; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.1); } }

/* ---------- rank list ---------- */
.ranks { display: grid; gap: 12px; max-width: 900px; }
.rank { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.rank .n { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--primary); font-weight: 700; }
.rank:nth-child(1) .n { box-shadow: 0 0 0 4px var(--primary-soft); }
.rank .name, .unscored .name { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.rank .name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.rank .tie, .unscored .tie { margin-left: 0; }
.tie { margin-left: 8px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--background); border: 1px solid var(--border); color: var(--muted-foreground); }
.copy { margin-top: 20px; }
.rank-tools { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.rank-tools .btn { min-height: 40px; }
.delta { flex: none; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid; font-variant-numeric: tabular-nums; }
.delta.up { color: hsl(142 55% 26%); background: hsl(142 45% 92%); border-color: hsl(142 40% 70%); }
.delta.down { color: hsl(0 70% 36%); background: hsl(0 85% 95%); border-color: hsl(0 70% 80%); }
.mv { flex: none; display: flex; gap: 6px; }
.mv button { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); line-height: 1; }
.mv button:hover:not(:disabled) { background: var(--primary-soft); border-color: var(--primary); }
.mv button:disabled { opacity: .35; cursor: default; }

/* ---------- sign in ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: 1fr; }
.auth-hero { padding: calc(env(safe-area-inset-top) + 40px) var(--gutter) 24px; display: flex; flex-direction: column; justify-content: center; gap: 20px; }
.auth-hero .brand img { width: 56px; height: 56px; border-radius: 14px; }
.auth-hero .brand b { font-size: 28px; }
.auth-hero .brand span { font-size: 14px; }
.auth-hero p { font-size: 17px; color: var(--muted-foreground); max-width: 46ch; }
.auth-form { padding: 8px var(--gutter) 48px; display: flex; align-items: flex-start; }
.auth-card { width: 100%; max-width: 420px; padding: 24px; display: grid; gap: 14px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted-foreground); font-size: 13px; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }

/* ---------- tablet and desktop ---------- */
@media (min-width: 900px) {
  .frame { grid-template-columns: var(--side) minmax(0, 1fr); }
  .side { display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100dvh; padding: 24px 16px;
    background: var(--card); border-right: 1px solid var(--border); }
  .side nav { display: grid; gap: 4px; }
  .side nav button { display: flex; align-items: center; gap: 10px; text-align: left; min-height: 44px; padding: 8px 12px; border-radius: 8px; font-size: 15px; }
  .side nav button .ico { display: inline; font-size: 18px; }
  .side nav button:hover { background: var(--background); }
  .side nav button[aria-current="page"] { background: var(--primary-soft); color: var(--foreground); }
  .acct { margin-top: auto; display: grid; gap: 4px; font-size: 13px; }
  .acct .who { color: var(--muted-foreground); overflow-wrap: anywhere; padding: 0 12px; }
  .acct .link { justify-self: start; }
  nav.bottom, .hdr-acct { display: none; }
  .hdr-brand img { display: none; }
  header { position: static; border-bottom: 0; padding-top: 32px; }
  header h1 { font-size: 28px; }
  main { padding-bottom: 64px; }
  .is-edit main, .is-edit.adding main { padding-bottom: 64px; }
  .total { top: 16px; }
  .auth { grid-template-columns: 1fr 1fr; }
  .auth-hero, .auth-form { padding: 64px clamp(32px, 6vw, 96px); align-items: center; }
  .auth-form { background: var(--card); border-left: 1px solid var(--border); justify-content: center; }
  .auth-card { box-shadow: none; border: 0; padding: 0; }
}
@media (min-width: 1100px) {
  .edit { grid-template-columns: 340px minmax(0, 1fr);
    grid-template-areas: "name doms" "total doms" "notes doms" "actions doms"; grid-template-rows: auto auto auto 1fr; column-gap: 28px; }
  .total { position: sticky; top: 16px; }
}
@media (max-width: 480px) {
  .save-ind[data-state="saving"] b, .save-ind[data-state="saved"] b { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .pick { grid-template-columns: 1fr; }
  .pick .muted { display: none; }
  .add { flex-wrap: nowrap; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } .save-ind i { animation-duration: 2s !important; } .verdict, .verdict::before, .verdict::after, .v-badge, .v-fill { animation: none !important; } }
