@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
  --radius: 0.875rem;
  --background: oklch(0.992 0.002 95);
  --foreground: oklch(0.16 0.012 260);
  --card: oklch(1 0 0);
  --muted: oklch(0.965 0.005 250);
  --muted-foreground: oklch(0.5 0.012 260);
  --border: oklch(0.91 0.008 250);
  --success: oklch(0.69 0.18 148);
  --success-soft: oklch(0.93 0.07 148);
  --destructive: oklch(0.6 0.22 27);
  --ink: oklch(0.16 0.018 260);
  --ink-foreground: oklch(0.985 0.003 95);
  --shadow-card: 0 1px 0 0 color-mix(in oklab, var(--foreground) 6%, transparent), 0 1px 2px 0 color-mix(in oklab, var(--foreground) 4%, transparent);
  --shadow-card-hover: 0 4px 12px -2px color-mix(in oklab, var(--foreground) 10%, transparent), 0 2px 4px -1px color-mix(in oklab, var(--foreground) 6%, transparent);
  --confetti-1: oklch(0.69 0.18 148);
  --confetti-2: oklch(0.72 0.16 240);
  --confetti-3: oklch(0.75 0.17 35);
  --confetti-4: oklch(0.72 0.15 295);
  --confetti-5: oklch(0.8 0.13 90);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}
h1, h2 { font-family: "Manrope", ui-sans-serif, system-ui, sans-serif; letter-spacing: -0.02em; margin: 0; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
::selection { background: color-mix(in oklab, var(--success) 35%, transparent); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

body { animation: appIn .5s var(--ease-out) both; }
@keyframes appIn { from { opacity: 0; } to { opacity: 1; } }

::view-transition-old(root), ::view-transition-new(root) { animation-duration: .32s; animation-timing-function: var(--ease-out); }

.view[hidden] { display: none !important; }

/* Shared keyframes */
@keyframes cardIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes squareIn { from { opacity: 0; transform: scale(.4); } to { opacity: 1; transform: scale(1); } }
@keyframes floatY { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }
@keyframes celebratePulse { 0% { text-shadow: 0 0 0 transparent; } 45% { text-shadow: 0 0 22px color-mix(in oklab, var(--success) 75%, transparent); } 100% { text-shadow: 0 0 0 transparent; } }
@keyframes barShine { from { transform: translateX(-120%); } to { transform: translateX(220%); } }
@keyframes confettiFall { to { transform: translateY(105vh) rotate(var(--rot, 480deg)); opacity: 0; } }
@keyframes ringPop { 0% { transform: scale(.85); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; border-radius: 9999px; font-size: 0.86rem; font-weight: 600; padding: 0.6rem 1.15rem; border: 1px solid transparent; cursor: pointer; transition: background-color .15s, border-color .15s, opacity .15s, transform .15s var(--ease-out), box-shadow .15s; white-space: nowrap; font-family: inherit; }
.btn:active { transform: scale(0.95); }
.btn-success { background: var(--success); color: oklch(0.18 0.04 148); font-weight: 700; }
.btn-success:hover { transform: scale(1.04); box-shadow: 0 6px 18px -6px color-mix(in oklab, var(--success) 55%, transparent); }
.btn-success svg { transition: transform .25s var(--ease-spring); }
.btn-success:hover svg { transform: rotate(90deg); }
.btn-outline { background: var(--card); color: var(--foreground); border-color: var(--border); }
.btn-outline:hover { border-color: color-mix(in oklab, var(--foreground) 30%, transparent); background: var(--muted); }
.btn-destructive { background: color-mix(in oklab, var(--destructive) 15%, transparent); color: var(--destructive); font-size: 0.78rem; padding: 0.5rem 0.9rem; transition: background-color .15s, color .15s, transform .15s; }
.btn-destructive:hover { background: color-mix(in oklab, var(--destructive) 22%, transparent); }
.btn-destructive.confirming { background: var(--destructive); color: white; animation: shake .4s var(--ease-out); }
.btn-icon { width: 2.35rem; height: 2.35rem; padding: 0; border-radius: 9999px; border: 1px solid var(--border); background: var(--card); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--foreground); flex-shrink: 0; transition: border-color .15s, background-color .15s, transform .15s var(--ease-out); }
.btn-icon:hover { border-color: color-mix(in oklab, var(--foreground) 40%, transparent); background: var(--muted); transform: translateX(-2px); }
.btn-icon:active { transform: scale(0.9); }
.btn:focus-visible, .btn-icon:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--success); outline-offset: 2px; }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1080px; margin: 0 auto; padding: 2rem 1.5rem 1.25rem;
  animation: cardIn .5s var(--ease-out) both;
}
.brand { font-family: "Manrope"; font-weight: 800; font-size: 1.3rem; }
.brand .dot { color: var(--success); display: inline-block; animation: floatY 2.4s ease-in-out infinite; }

/* Board */
.board-wrap { max-width: 1080px; margin: 0 auto; padding: 0.5rem 1.5rem 4rem; }
.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }

.grid-card {
  border: 1px solid var(--border); border-radius: 1.5rem; background: var(--card);
  box-shadow: var(--shadow-card); padding: 1.35rem; cursor: pointer;
  transition: box-shadow .2s, transform .2s var(--ease-out); display: flex; gap: 1rem; align-items: center;
  text-align: left; opacity: 0; animation: cardIn .5s var(--ease-out) forwards;
  animation-delay: calc(var(--i, 0) * 55ms);
}
.grid-card:hover { box-shadow: var(--shadow-card-hover); transform: translateY(-3px) scale(1.01); }
.grid-card:active { transform: translateY(-1px) scale(0.99); }
.grid-card:focus-visible { outline: 2px solid var(--success); outline-offset: 2px; }
.grid-card .ring-wrap { position: relative; width: 56px; height: 56px; flex-shrink: 0; }
.grid-card .ring-wrap svg { transform: rotate(-90deg); width: 56px; height: 56px; }
.grid-card .ring-bg { fill: none; stroke: var(--muted); stroke-width: 3.2; }
.grid-card .ring-fill { fill: none; stroke: var(--success); stroke-width: 3.2; stroke-linecap: round; transition: stroke-dasharray .9s var(--ease-out); transition-delay: calc(var(--i, 0) * 55ms + .1s); }
.grid-card .ring-pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: "JetBrains Mono"; font-size: 0.68rem; font-weight: 600; }
.grid-card .info { min-width: 0; flex: 1; }
.grid-card .name { font-family: "Manrope"; font-weight: 700; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-card .count { color: var(--muted-foreground); font-size: 0.82rem; margin-top: 0.2rem; font-family: "JetBrains Mono"; }

/* State box (empty) */
.state-box { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 1px solid var(--border); border-radius: 1.75rem; padding: 4rem 1.5rem; box-shadow: var(--shadow-card); gap: 0.35rem; margin-top: 1rem; opacity: 0; animation: cardIn .5s var(--ease-out) forwards; }
.state-box .icon { color: color-mix(in oklab, var(--muted-foreground) 40%, transparent); margin-bottom: 0.5rem; }
.state-box .icon svg { display: block; animation: floatY 3s ease-in-out infinite; }
.state-box .title { color: var(--foreground); font-weight: 600; font-size: 1rem; }
.state-box .sub { color: var(--muted-foreground); font-size: 0.85rem; }

/* Detail view */
.detail-view { min-height: 100vh; display: flex; flex-direction: column; }
.detail-header { display: flex; align-items: center; gap: 1rem; max-width: 1080px; width: 100%; margin: 0 auto; padding: 1.5rem 1.5rem 0.5rem; animation: cardIn .4s var(--ease-out) both; }
.detail-title-wrap { flex: 1; min-width: 0; }
.detail-name { font-size: 1.4rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-name.celebrate { animation: celebratePulse 1.3s ease; }
.detail-stats { color: var(--muted-foreground); font-size: 0.85rem; margin-top: 0.2rem; font-family: "JetBrains Mono"; }
.detail-progress { max-width: 1080px; width: 100%; margin: 0.75rem auto 0; padding: 0 1.5rem; animation: cardIn .4s var(--ease-out) .05s both; }
.detail-progress .bar { height: 8px; border-radius: 9999px; background: var(--muted); overflow: hidden; position: relative; }
.detail-progress .bar::after { content: ''; display: block; height: 100%; width: var(--pct, 0%); background: var(--success); border-radius: 9999px; transition: width .6s var(--ease-out); }
.detail-progress .bar::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 40%;
  background: linear-gradient(90deg, transparent, color-mix(in oklab, white 60%, transparent), transparent);
  animation: barShine 1.8s ease-in-out infinite; opacity: .5; mix-blend-mode: overlay;
}

.squares-scroll { flex: 1; max-width: 1080px; width: 100%; margin: 0 auto; padding: 1.5rem; }
.squares-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(22px, 1fr)); gap: 6px; }
.square {
  aspect-ratio: 1; border-radius: 5px; border: 1px solid var(--border); background: var(--muted);
  cursor: pointer; transition: background-color .15s, border-color .15s, transform .15s var(--ease-out); padding: 0;
  position: relative; opacity: 0; animation: squareIn .32s var(--ease-spring) both;
}
.square:hover { border-color: color-mix(in oklab, var(--foreground) 30%, transparent); transform: scale(1.08); }
.square:active { transform: scale(0.85); }
.square.filled { background: var(--success); border-color: transparent; }
.square:focus-visible { outline: 2px solid var(--success); outline-offset: 1px; }
.square-burst {
  position: absolute; inset: -3px; border-radius: inherit; background: var(--success);
  pointer-events: none; z-index: -1;
}

/* Confetti */
.confetti-layer { position: fixed; inset: 0; z-index: 1000; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; opacity: 0.9; animation: confettiFall linear forwards; }

/* Modal */
.modal-live-overlay {
  position: fixed; inset: 0; z-index: 999; display: flex; align-items: center; justify-content: center; padding: 1rem;
  background: color-mix(in oklab, var(--foreground) 40%, transparent); backdrop-filter: blur(0px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .22s var(--ease-out), backdrop-filter .22s var(--ease-out), visibility 0s linear .22s;
}
.modal-live-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; backdrop-filter: blur(4px); transition: opacity .22s var(--ease-out), backdrop-filter .22s var(--ease-out); }
.modal-live-panel { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 1.75rem; box-shadow: 0 20px 50px -12px rgba(0,0,0,.4); transform: scale(.94) translateY(10px); opacity: 0; transition: transform .22s var(--ease-spring), opacity .18s var(--ease-out); }
.modal-live-overlay.open .modal-live-panel { transform: scale(1) translateY(0); opacity: 1; }
.modal-live-panel .mh { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-live-panel .mh-title { font-family: "Manrope"; font-weight: 700; font-size: 1.05rem; }
.modal-live-panel .mb { padding: 1.25rem; }
.modal-live-panel .mf { display: flex; gap: 0.5rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); justify-content: flex-end; }

label.field-label { display: block; margin-bottom: 0.4rem; font-size: 0.83rem; font-weight: 600; }
.input { width: 100%; border-radius: 1rem; border: 1px solid var(--border); background: var(--background); padding: 0.6rem 1rem; font-size: 0.87rem; color: var(--foreground); outline: none; font-family: inherit; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: color-mix(in oklab, var(--foreground) 40%, transparent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--foreground) 8%, transparent); }
.field { margin-bottom: 1.1rem; }
.field:last-child { margin-bottom: 0; }
.field-hint { font-size: 0.76rem; color: var(--muted-foreground); margin: 0.4rem 0 0; }
.error-banner { border-radius: 0.85rem; padding: 0.55rem 0.8rem; font-size: 0.82rem; background: color-mix(in oklab, var(--destructive) 15%, transparent); color: var(--destructive); margin-bottom: 1rem; animation: shake .4s var(--ease-out); }

@media (max-width: 560px) {
  .app-header { padding: 1.5rem 1.15rem 1rem; }
  .board-wrap { padding: 0.5rem 1.15rem 3rem; }
  .detail-header { padding: 1.15rem 1.15rem 0.5rem; flex-wrap: wrap; }
  .detail-progress { padding: 0 1.15rem; }
  .squares-scroll { padding: 1.15rem; }
  .btn-destructive span { display: none; }
}
