:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #1d2522;
  --muted: #66706c;
  --line: #ddd5c9;
  --primary: #315c51;
  --primary-soft: #dfece5;
  --rose: #b85b69;
  --rose-soft: #f7e5e8;
  --gold: #ad7b2c;
  --gold-soft: #f4ead6;
  --blue: #426f8d;
  --blue-soft: #e1edf3;
  --shadow: 0 18px 44px rgba(43, 48, 45, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(49, 92, 81, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(49, 92, 81, 0.04) 1px, transparent 1px),
    var(--bg);
  background-size: 34px 34px;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 1180px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.app-header,
.section-head,
.dialog-head,
.row-topline,
.project-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.app-header {
  padding-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand img {
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(49, 92, 81, 0.18);
}

.brand h1 {
  font-size: 25px;
  line-height: 1.05;
}

.brand p,
.muted,
.project-meta,
.dialog-copy,
.row-instruction,
details,
.empty-state {
  color: var(--muted);
}

.brand p {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.view {
  display: none;
  align-content: start;
  gap: 18px;
  min-width: 0;
  padding-bottom: 94px;
}

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

.section-title,
.section-block,
.upload-panel,
.project-detail {
  display: grid;
  gap: 14px;
}

.upload-panel,
.project-detail,
.progress-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  padding: 16px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  font-size: 22px;
  line-height: 1.15;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.upload-tile {
  display: grid;
  gap: 9px;
  min-height: 126px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 14px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(43, 48, 45, 0.06);
}

.upload-tile:nth-child(2) {
  background: linear-gradient(180deg, #ffffff, #f8eff1);
}

.upload-tile:nth-child(3) {
  background: linear-gradient(180deg, #ffffff, #eef5f8);
}

.upload-tile:focus-within,
.upload-tile:hover {
  border-color: var(--primary);
}

.tile-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 34px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.upload-tile:nth-child(2) .tile-icon {
  background: var(--rose-soft);
  color: var(--rose);
}

.upload-tile:nth-child(3) .tile-icon {
  background: var(--blue-soft);
  color: var(--blue);
}

.upload-tile strong {
  align-self: end;
  font-size: 16px;
  line-height: 1.15;
}

.upload-tile small,
.project-card small,
.project-progress {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.analysis-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid #cbded5;
  border-radius: 8px;
  background: var(--primary-soft);
  padding: 12px;
}

.analysis-status[hidden] {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(49, 92, 81, 0.22);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.dashboard-strip,
.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.dashboard-strip article,
.profile-grid article {
  display: grid;
  gap: 7px;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 14px;
  box-shadow: 0 8px 24px rgba(43, 48, 45, 0.06);
}

.dashboard-strip span,
.profile-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.dashboard-strip strong,
.profile-grid strong {
  align-self: end;
  font-size: 24px;
  line-height: 1;
}

.project-list,
.row-list {
  display: grid;
  gap: 12px;
}

.project-card,
.row-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 12px;
  box-shadow: 0 8px 24px rgba(43, 48, 45, 0.06);
}

.project-card.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(49, 92, 81, 0.12), 0 8px 24px rgba(43, 48, 45, 0.06);
}

.project-card.is-completed .project-symbol {
  background: var(--gold-soft);
  color: var(--gold);
}

.project-main {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.project-symbol {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
}

.project-title {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.25;
}

.project-meta {
  display: block;
  margin-top: 4px;
  line-height: 1.35;
}

.mini-progress,
.progress-track {
  overflow: hidden;
  border-radius: 999px;
  background: #e7dfd3;
}

.mini-progress {
  flex: 1;
  height: 7px;
}

.mini-progress span,
.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--primary);
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(430px, calc(100vw - 24px));
  transform: translateX(-50%);
  border: 1px solid rgba(221, 213, 201, 0.9);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  padding: 6px;
  box-shadow: 0 18px 52px rgba(43, 48, 45, 0.18);
  backdrop-filter: blur(16px);
}

.tab-button,
.segment,
.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button,
.row-check {
  border-radius: 8px;
  cursor: pointer;
}

.tab-button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 54px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.tab-button > span:first-child {
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  color: inherit;
  font-size: 18px;
  line-height: 1;
}

.tab-button.is-active {
  background: var(--primary);
  color: white;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 4px;
}

.segment {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 11px;
  font-size: 13px;
  font-weight: 850;
}

.segment.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

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

.status-pill,
.confidence-pill {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
}

.status-pill.is-completed {
  background: var(--gold-soft);
  color: var(--gold);
}

.progress-panel {
  display: grid;
  gap: 12px;
  box-shadow: none;
}

.progress-panel > div:first-child {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.progress-panel span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.progress-panel strong {
  font-size: 18px;
}

.progress-track {
  height: 10px;
}

.row-card.is-done {
  background: #fbfaf5;
}

.row-topline {
  align-items: flex-start;
}

.row-check {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: white;
  color: var(--primary);
  font-weight: 900;
}

.row-card.is-done .row-check {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.row-card h3 {
  font-size: 17px;
  line-height: 1.25;
}

.row-instruction {
  margin-top: 4px;
  line-height: 1.45;
}

details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 13px;
}

summary {
  width: max-content;
  color: var(--primary);
  cursor: pointer;
  font-weight: 850;
}

details p {
  margin-top: 8px;
  line-height: 1.45;
}

.stitch-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stitch-box {
  display: grid;
  gap: 4px;
  min-height: 64px;
  border-radius: 8px;
  background: #f7f1e6;
  padding: 10px;
}

.stitch-box:nth-child(2) {
  background: var(--primary-soft);
}

.stitch-box:nth-child(3) {
  background: var(--rose-soft);
}

.stitch-box:nth-child(4) {
  background: var(--blue-soft);
}

.stitch-box span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.stitch-box strong {
  font-size: 18px;
}

.empty-state {
  border: 1px dashed #cfc4b5;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.75);
  padding: 16px;
  line-height: 1.45;
}

.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.secondary-button {
  border-color: #c8dbd2;
  background: var(--primary-soft);
  color: var(--primary);
}

.ghost-button {
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

.text-button {
  min-height: 34px;
  border-color: var(--line);
  background: rgba(255, 253, 248, 0.82);
  color: var(--primary);
  padding: 0 10px;
  font-size: 13px;
}

.icon-button {
  width: 40px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

dialog {
  width: min(460px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(43, 48, 45, 0.28);
}

dialog::backdrop {
  background: rgba(29, 37, 34, 0.38);
}

.dialog-card {
  display: grid;
  gap: 16px;
  padding: 16px;
  background: var(--surface-strong);
}

.dialog-actions {
  display: flex;
  gap: 10px;
}

.dialog-actions button {
  flex: 1;
}

.legal-card {
  max-height: min(760px, calc(100vh - 32px));
  overflow: auto;
}

.legal-section {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  color: #38443f;
  font-size: 14px;
  line-height: 1.5;
}

.legal-section h3 {
  font-size: 17px;
}

.legal-section address {
  font-style: normal;
}

.legal-section a {
  color: var(--primary);
  font-weight: 800;
}

@media (min-width: 900px) {
  .app-shell {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 22px;
  }

  .app-header {
    grid-column: 1 / -1;
  }

  .tabbar {
    position: sticky;
    top: 16px;
    left: auto;
    bottom: auto;
    align-self: start;
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: 1fr;
    width: auto;
    transform: none;
    box-shadow: var(--shadow);
  }

  .tab-button {
    grid-template-columns: 28px minmax(0, 1fr);
    justify-items: start;
    padding: 0 14px;
  }

  .view.is-active {
    grid-column: 2;
    grid-row: 2;
    padding-bottom: 18px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .upload-grid,
  .dashboard-strip,
  .profile-grid,
  .stitch-summary {
    grid-template-columns: 1fr;
  }

  .section-head,
  .detail-hero,
  .progress-panel > div:first-child {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }

  .upload-tile {
    min-height: 98px;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
  }

  .upload-tile small {
    grid-column: 2;
  }

  .confidence-pill {
    align-self: flex-start;
  }
}
