:root {
  color-scheme: light;
  --bg: #f7f3e8;
  --panel: #ffffff;
  --field: #fbfcf8;
  --ink: #171717;
  --muted: #5f6470;
  --line: #222222;
  --soft-line: #ded8c8;
  --accent: #d9281e;
  --accent-strong: #a81813;
  --pop: #f7c948;
  --blue: #2563eb;
  --cyan: #12b5cb;
  --warn: #a16207;
  --danger: #b91c1c;
  --shadow: 5px 6px 0 rgba(23, 23, 23, 0.16);
  --dot: rgba(23, 23, 23, 0.075);
  --wash-start: #fff9e9;
  --wash-end: #eef4f8;
  --panel-wash: rgba(247, 201, 72, 0.12);
  --card-wash: rgba(18, 181, 203, 0.08);
  --progress-empty: #ece6d6;
  --owned-fill: #eef1ea;
  --cover-a: rgba(247, 201, 72, 0.9);
  --cover-b: rgba(18, 181, 203, 0.35);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111815;
  --panel: #1a2420;
  --field: #121a17;
  --ink: #eef8f2;
  --muted: #a1b5aa;
  --line: #d8fbe8;
  --soft-line: #355346;
  --accent: #22c55e;
  --accent-strong: #86efac;
  --pop: #34d399;
  --blue: #0ea5e9;
  --cyan: #10b981;
  --warn: #facc15;
  --danger: #f87171;
  --shadow: 5px 6px 0 rgba(0, 0, 0, 0.38);
  --dot: rgba(52, 211, 153, 0.16);
  --wash-start: #101715;
  --wash-end: #15231e;
  --panel-wash: rgba(34, 197, 94, 0.12);
  --card-wash: rgba(16, 185, 129, 0.12);
  --progress-empty: #2b3d35;
  --owned-fill: #223129;
  --cover-a: rgba(34, 197, 94, 0.5);
  --cover-b: rgba(14, 165, 233, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8px 8px, var(--dot) 0 1.1px, transparent 1.6px) 0 0 / 16px 16px,
    linear-gradient(180deg, var(--wash-start) 0%, var(--bg) 48%, var(--wash-end) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 18px 14px 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: max(12px, env(safe-area-inset-top)) 2px 14px;
}

.topbar h1 {
  color: var(--ink);
  text-shadow: 2px 2px 0 var(--pop), 3px 3px 0 rgba(217, 40, 30, 0.2);
}

:root[data-theme="dark"] .topbar h1 {
  text-shadow: 0 0 16px rgba(34, 197, 94, 0.45), 2px 2px 0 rgba(0, 0, 0, 0.65);
}

.eyebrow,
.status-label {
  display: block;
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.55rem;
  line-height: 1.05;
  font-weight: 950;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.05rem;
  font-weight: 950;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 3px 3px 0 rgba(23, 23, 23, 0.14);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: 68px;
  height: 36px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 3px 3px 0 rgba(23, 23, 23, 0.14);
}

.theme-icon {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  font-weight: 950;
}

.theme-knob {
  position: absolute;
  left: 4px;
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--pop);
  transition: transform 160ms ease, background 160ms ease;
}

.theme-switch[aria-checked="true"] .theme-knob {
  transform: translateX(32px);
  background: var(--accent);
}

.icon-button span {
  font-size: 1.4rem;
  line-height: 1;
}

.status-strip {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.status-strip > div,
.search-panel,
.toolbar {
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--panel-wash), transparent 34%),
    var(--panel);
}

.status-strip > div {
  min-width: 0;
  padding: 12px;
}

.status-strip strong {
  display: block;
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-panel {
  margin-bottom: 12px;
  padding: 12px;
}

.search-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 2px solid var(--soft-line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
}

input {
  padding: 0 12px;
}

select {
  padding: 0 34px 0 10px;
}

.text-button,
.tab {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

.text-button {
  min-height: 42px;
  padding: 0 12px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.detail-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.tab {
  min-width: 0;
  min-height: 42px;
  padding: 0 4px;
  font-size: 0.83rem;
}

.detail-tab {
  min-height: 40px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 900;
}

.tab.is-active,
.detail-tab.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: inset 0 -3px 0 rgba(23, 23, 23, 0.18);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
  padding: 10px;
}

.commit-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.uses-worker-sync .commit-bar {
  grid-template-columns: 1fr;
}

.uses-worker-sync #syncSettings {
  display: none;
}

.commit-button {
  min-height: 42px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 950;
  box-shadow: 3px 3px 0 rgba(23, 23, 23, 0.14);
}

.commit-button:disabled {
  background: var(--owned-fill);
  color: var(--muted);
}

.view-toggle {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin: -4px 0 12px;
}

.layout-button {
  display: grid;
  width: 42px;
  height: 38px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 950;
}

.layout-button.is-active {
  background: var(--cyan);
  color: #fff;
  box-shadow: inset 0 -3px 0 rgba(23, 23, 23, 0.18);
}

.section-heading {
  margin: 0 2px 10px;
}

.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.run-list,
.issue-list {
  display: grid;
  gap: 9px;
}

.run-card,
.issue-row {
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, var(--card-wash), transparent 42%),
    var(--panel);
  box-shadow: 4px 4px 0 rgba(23, 23, 23, 0.12);
}

.run-button {
  display: grid;
  width: 100%;
  gap: 8px;
  padding: 13px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.run-title {
  overflow-wrap: anywhere;
  font-weight: 900;
  line-height: 1.2;
}

.run-meta,
.missing-preview,
.issue-meta,
.issue-note {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.progress-track {
  display: block;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--progress-empty);
}

.progress-bar {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
}

.issue-row {
  position: relative;
  display: grid;
  grid-template-columns: 42px 58px 1fr;
  gap: 10px;
  align-items: start;
  padding: 11px;
}

.pick-button {
  width: 38px;
  height: 38px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.pick-button::before {
  content: "+";
  color: var(--accent-strong);
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
}

.issue-row.is-picked .pick-button {
  border-color: var(--accent);
  background: var(--accent);
}

.issue-row.is-picked .pick-button::before {
  content: "✓";
  color: #fff;
}

.issue-row.is-owned .pick-button::before {
  content: "↺";
  color: var(--accent-strong);
}

.issue-row.is-owned .pick-button {
  background: var(--owned-fill);
}

.cover-slot {
  position: relative;
  width: 58px;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(135deg, var(--cover-a), var(--cover-b)),
    var(--field);
}

.issue-cover {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.has-cover .issue-cover {
  display: block;
}

.cover-upload {
  position: absolute;
  inset: auto 5px 5px auto;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--accent-strong);
  font-weight: 950;
  line-height: 1;
  box-shadow: 2px 2px 0 rgba(23, 23, 23, 0.16);
}

.cover-delete {
  position: absolute;
  inset: 5px 5px auto auto;
  display: none;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 950;
  line-height: 1;
  box-shadow: 2px 2px 0 rgba(23, 23, 23, 0.16);
}

.has-cover .cover-delete {
  display: grid;
}

.cover-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.issue-list.is-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.issue-list.is-grid .issue-row {
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 9px;
}

.issue-list.is-grid .pick-button {
  position: absolute;
  z-index: 1;
  width: 34px;
  height: 34px;
  margin: 6px;
}

.issue-list.is-grid .cover-slot {
  width: 100%;
  min-height: 168px;
}

.issue-list.is-grid .issue-title {
  font-size: 0.9rem;
}

.issue-list.is-grid .issue-meta,
.issue-list.is-grid .issue-note {
  font-size: 0.78rem;
}

.issue-title {
  display: block;
  margin-bottom: 2px;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.issue-note {
  margin: 5px 0 0;
}

.empty-state,
.error-state {
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  text-align: center;
}

.error-state {
  border-color: rgba(185, 28, 28, 0.35);
  color: var(--danger);
}

dialog {
  width: min(94vw, 680px);
  max-height: 88vh;
  overflow: auto;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(17, 24, 39, 0.56);
}

.dialog-head {
  position: sticky;
  top: -14px;
  z-index: 2;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin: -14px -14px 12px;
  padding: 14px;
  border-bottom: 2px solid var(--line);
  background: var(--bg);
}

.dialog-head h2 {
  margin-bottom: 0;
  overflow-wrap: anywhere;
  font-size: 1.22rem;
}

.dialog-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.dialog-stats span {
  display: block;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.8rem;
}

.dialog-stats strong {
  display: block;
  color: var(--ink);
  font-size: 1rem;
}

.settings-form {
  display: grid;
  gap: 12px;
}

.settings-help {
  margin: 0;
  border: 2px solid var(--soft-line);
  border-radius: 8px;
  padding: 10px;
  background: var(--field);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.35;
}

.settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.toast-region {
  position: fixed;
  right: 12px;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 12px;
  z-index: 20;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  justify-self: center;
  width: min(100%, 420px);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 900;
  line-height: 1.3;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-success {
  border-color: var(--accent);
}

.toast.is-error {
  border-color: var(--danger);
}

.toast.is-fanfare {
  position: relative;
  overflow: hidden;
  border-color: var(--pop);
  background:
    radial-gradient(circle at 16px 16px, rgba(255, 255, 255, 0.44) 0 3px, transparent 4px),
    linear-gradient(135deg, var(--pop), var(--accent) 52%, var(--cyan));
  color: #111815;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.35);
}

.toast.is-fanfare::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 12%, rgba(255, 255, 255, 0.35) 12% 15%, transparent 15% 36%, rgba(255, 255, 255, 0.28) 36% 39%, transparent 39% 100%);
  transform: translateX(-100%);
  animation: shine 900ms ease-out 120ms;
}

.toast.is-hiding {
  opacity: 0;
  transform: translateY(8px);
}

@keyframes shine {
  to {
    transform: translateX(100%);
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 10px;
  }

  .status-strip {
    grid-template-columns: 1fr 1fr;
  }

  .status-strip > div:first-child {
    grid-column: 1 / -1;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .commit-bar {
    grid-template-columns: 1fr;
  }
}
