:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #21252e;
  --text: #f1f3f7;
  --muted: #8a92a3;
  --accent: #5b9cff;
  --danger: #ff5d5d;
  --positive: #4ad08a;
  --negative: #ffb454;
  --radius: 14px;
  --gap: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eceef2;
    --text: #14171c;
    --muted: #5d6577;
    --accent: #2d6cff;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 12px) 16px 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.topbar h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
.icon-btn:active { transform: scale(0.96); }

.counter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
}
@media (min-width: 520px) {
  .counter-list { grid-template-columns: repeat(3, 1fr); }
}

.counter-item {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  transition: transform 0.12s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.counter-item:active { transform: scale(0.97); }
.counter-item:hover { box-shadow: 0 3px 14px rgba(0,0,0,0.08); }

/* Direction accent: soft colored wash in the bottom-left corner */
.counter-item::before {
  content: '';
  position: absolute;
  left: -40%;
  bottom: -40%;
  width: 90%;
  height: 90%;
  border-radius: 50%;
  background: transparent;
  filter: blur(28px);
  opacity: 0.35;
  pointer-events: none;
}
.counter-item.is-past::before { background: var(--positive); }
.counter-item.is-future::before { background: var(--negative); }

.counter-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  position: relative;
  z-index: 1;
}
.counter-emoji {
  font-size: 40px;
  line-height: 1;
  flex: 0 0 auto;
}
.counter-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.counter-value {
  align-self: flex-end;
  text-align: right;
  line-height: 1;
  width: 100%;
  position: relative;
  z-index: 1;
}
.counter-value .big {
  font-size: clamp(38px, 10vw, 54px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.counter-value .unit {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}
.counter-value.positive .big { color: var(--positive); }
.counter-value.negative .big { color: var(--negative); }

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 40px;
}

/* Dialog / sheet */
dialog.sheet {
  border: none;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(560px, calc(100% - 24px));
  max-height: 90vh;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}
dialog.sheet::backdrop {
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}

dialog.sheet form,
dialog.sheet article {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px 18px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.sheet-head h2 { font-size: 18px; margin: 0; }

.link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  cursor: pointer;
  padding: 6px 4px;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  border: none;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s;
}
.icon-link:hover { background: color-mix(in srgb, var(--surface-2) 70%, var(--accent) 30%); }
.icon-link:active { transform: scale(0.94); }
.icon-link svg { display: block; }

.row {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  gap: 10px;
}
.row.column {
  grid-template-columns: 1fr;
  align-items: start;
}
.row > span {
  color: var(--muted);
  font-size: 14px;
}

.row input, .row textarea {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
}
.row input:focus, .row textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.date-picker {
  position: relative;
  width: 100%;
}
.date-picker input[type="text"] {
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  caret-color: transparent;
}
.date-picker input[type="date"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  border: 0;
  padding: 0;
}

.sheet-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

button.primary {
  flex: 1;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* Detail */
.detail-hero {
  text-align: center;
  padding: 8px 0 4px;
}
.detail-emoji {
  font-size: 56px;
  line-height: 1;
}
.detail-hero h2.detail-name {
  margin: 8px 0 0;
  font-size: 20px;
  font-weight: 600;
}
.detail-count {
  font-size: 44px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.detail-sub {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}
.detail-desc {
  white-space: pre-wrap;
  color: var(--text);
  background: var(--surface-2);
  padding: 12px 14px;
  border-radius: 12px;
  margin: 4px 0 0;
  min-height: 8px;
}
.detail-desc:empty { display: none; }
.detail-actions { display: flex; gap: 10px; margin-top: 6px; }
