:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --danger: #b91c1c;
  --warning: #b45309;
  --radius: 12px;
  --tabbar-height: 60px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #1f2937;
    --primary: #14b8a6;
    --primary-text: #042f2e;
    --danger: #f87171;
    --warning: #fbbf24;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
}

a { color: var(--primary); }

h1 { font-size: 1.4rem; margin: 0 0 12px; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
}

.brand { color: var(--primary-text); font-weight: 700; text-decoration: none; }

.content { max-width: 720px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.tab.active { color: var(--primary); }

.filters { display: flex; gap: 8px; margin-bottom: 12px; }

.chip {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
}

.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  display: block;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-title { font-size: 1rem; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; color: var(--muted); font-size: 0.9rem; }
.card-deadline { margin-top: 6px; font-size: 0.9rem; }
.card-deadline.soon { color: var(--warning); font-weight: 600; }
.card-deadline.past { color: var(--muted); text-decoration: line-through; }

.badge {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--border);
  color: var(--text);
  white-space: nowrap;
}

.badge-entered, .badge-draw_pending { background: #dbeafe; color: #1e3a8a; }
.badge-won, .badge-prize_received, .badge-realized { background: #dcfce7; color: #14532d; }
.badge-excluded, .badge-expired, .badge-not_won, .badge-presumed_not_won { opacity: 0.7; }

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); width: 100%; }
.button.danger { color: var(--danger); }

.detail-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }

.prizes { padding-left: 20px; }
.prizes li { margin-bottom: 6px; }
.prizes small { display: block; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.notes { white-space: pre-wrap; }
.muted { color: var(--muted); }

.actions { display: flex; gap: 10px; margin-top: 24px; }

.form fieldset, .form details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px 14px;
  margin: 0 0 14px;
}

.form legend, .form summary { font-weight: 700; padding: 0 4px; }
.form summary { cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field label { font-size: 0.9rem; color: var(--muted); }

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.field.invalid input, .field.invalid select { border-color: var(--danger); }
.error, .form-error { color: var(--danger); }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0; }

.row { display: flex; gap: 10px; }

.prize-row { border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 4px; }
.prize-number { color: var(--muted); font-size: 0.8rem; font-weight: 700; }

.tab { font-size: 0.85rem; }

.summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat strong { font-size: 1.1rem; }
.stat small { color: var(--muted); }

.rate {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--primary);
  color: var(--primary-text);
  white-space: nowrap;
}

li.card .card-title { color: var(--text); font-weight: 700; text-decoration: none; }

.entry-actions { display: flex; gap: 8px; margin-top: 10px; }
.entry-actions > * { flex: 1; }
.entry-actions form { display: flex; }
.entry-actions .button { width: 100%; white-space: nowrap; padding-left: 10px; padding-right: 10px; }

.exclusion { color: var(--danger); font-weight: 600; }
.notice { color: var(--primary); font-weight: 600; }
.hidden-note { text-align: center; margin-top: 16px; }
.entries { padding-left: 20px; color: var(--muted); }

.app-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.header-new {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-text);
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--primary-text);
  text-decoration: none;
  font-size: 1.1rem;
}

.button.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.card .button.small { margin-top: 10px; }

.notice-banner { margin-bottom: 12px; display: grid; gap: 8px; justify-items: end; }
.notice-banner .notices { width: 100%; }
.notices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.notice-item a {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.notice-item.unread a { border-left-color: var(--warning); }
.notice-item span { color: var(--muted); font-size: 0.9rem; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
}
.timeline-item.kind-claim { border-left-color: var(--danger); }
.timeline-item.kind-deadline { border-left-color: var(--warning); }
.timeline-item.kind-draw { border-left-color: var(--primary); }
.timeline-date { display: flex; flex-direction: column; }
.timeline-date small, .timeline-kind { color: var(--muted); }
.timeline-body { display: flex; flex-direction: column; min-width: 0; }
.timeline-body a { color: var(--text); font-weight: 600; text-decoration: none; }
.group-overdue { color: var(--danger); }
.group-past { color: var(--muted); }

.hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.hero small, .hero span { color: var(--muted); }
.hero-value { font-size: 2rem; line-height: 1.1; }
.progress { margin-top: 8px; }
.progress-bar {
  display: block; width: 100%; height: 8px; border: 0; border-radius: 999px;
  appearance: none; -webkit-appearance: none; background: var(--border); overflow: hidden;
}
.progress-bar::-webkit-progress-bar { background: var(--border); border-radius: 999px; }
.progress-bar::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
.progress-bar::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
.progress small { display: block; margin-top: 4px; }

.breakdown { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.breakdown th, .breakdown td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.breakdown th:first-child, .breakdown td:first-child { text-align: left; }
.breakdown th { color: var(--muted); font-weight: 600; }
.breakdown td:not(:first-child) { white-space: nowrap; }

body.login { padding-bottom: 0; }
body.login .content { max-width: 420px; padding-top: 15vh; }
.logout { margin-top: 24px; }

.claude-button { width: 100%; margin: -4px 0 12px; }
.notice-box {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: var(--surface);
}
.notice-box.problem { border-color: var(--danger); color: var(--danger); }
.filtered { margin-top: 16px; }
.filtered summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.candidates-link { display: block; margin-bottom: 12px; }
.warnings { list-style: none; padding: 0; margin: 8px 0; color: var(--danger); font-size: 0.9rem; }
/* Buttons keep their label on one line, so rows wrap instead of overflowing. */
.entry-actions { flex-wrap: wrap; }
.entry-actions > * { min-width: 140px; }
.card-meta .source { font-size: 0.8rem; padding: 0 6px; border: 1px solid var(--border); border-radius: 999px; }
.also-listed { font-size: 0.85rem; margin: 4px 0 0; }
.export-links { margin-top: 0; flex-wrap: wrap; }
.fill-helper { margin-top: 8px; }
.fill-helper summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.copy-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.copy {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.copy.copied { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.copy.copied::after { content: " ✓"; }
.rate.estimate { background: var(--border); color: var(--text); }
.card-meta .region.local { color: var(--primary); font-weight: 600; }
.estimate-line { font-size: 0.85rem; margin: 4px 0 0; }
.bulk { margin: 0 0 10px; }
.source-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.source-actions .button.small { min-height: 32px; padding: 4px 10px; font-size: 0.8rem; }
.terms-text { white-space: pre-wrap; word-break: break-word; font: 0.85rem/1.5 ui-monospace, monospace; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.hash { word-break: break-all; font-family: ui-monospace, monospace; font-size: 0.8rem; }
.source-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.source-item { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.source-item small { display: block; }
.source-item .source-actions { justify-content: flex-start; margin-top: 8px; }
.source-item .bulk { margin: 0; }

.answer-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.answer-row label { font-weight: 600; }
.answer-row input { flex: 1; min-width: 0; }
