*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-dark:  #1b5e20;
  --green-mid:   #2e7d32;
  --green-light: #e8f5e9;
  --cell-a: #c8e6c9;
  --cell-b: #b2dfdb;
  --cell-c: #fff9c4;
  --cell-d: #f8bbd0;
  --nav-h: 54px;
  --hdr-h: 48px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--green-light);
  color: #212121;
}

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
}

header {
  height: var(--hdr-h);
  background: var(--green-mid);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 2.5%;
  gap: 6px;
}
.view.active { display: flex; }

.instruction {
  font-size: 0.8rem;
  color: #555;
  text-align: center;
  line-height: 1.4;
  flex-shrink: 0;
}

.stats-instructions {
  font-size: 0.78rem;
  color: #777;
  text-align: center;
  line-height: 1.5;
  padding-top: 6px;
  flex-shrink: 0;
}

/* ── Carroll Wrapper ── */
.carroll-wrap {
  flex: 1;
  display: grid;
  grid-template-areas:
    ". top"
    "left grid";
  grid-template-columns: 24px 1fr;
  grid-template-rows: 24px 1fr;
  gap: 4px;
  min-height: 0;
}

.axis-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--green-dark);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
}
.axis-top  { grid-area: top; }
.axis-left { grid-area: left; writing-mode: vertical-rl; transform: rotate(180deg); }

/* ── Carroll Diagram Grid ── */
.carroll-diagram {
  grid-area: grid;
  display: grid;
  grid-template-columns: 56px 1fr 1fr;
  grid-template-rows: 44px 1fr 1fr;
  gap: 4px;
  min-height: 0;
}

.c-corner { /* empty top-left */ }

.c-col-hdr {
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 600;
  border-radius: 6px;
  line-height: 1.3;
  padding: 4px 2px;
}

.c-row-hdr {
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 600;
  border-radius: 6px;
  line-height: 1.3;
  padding: 4px 2px;
}

/* ── Cells ── */
.carroll-cell {
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: filter 0.12s, transform 0.1s;
  position: relative;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.carroll-cell:active { transform: scale(0.95); filter: brightness(0.92); }

.cell-lb-vb { background: var(--cell-a); }
.cell-lb-vc { background: var(--cell-b); }
.cell-lc-vb { background: var(--cell-c); }
.cell-lc-vc { background: var(--cell-d); }

/* classify cell content */
.cell-icons {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
}

.cell-icons svg { flex-shrink: 0; }

.cell-sep {
  width: 1px;
  height: 28px;
  background: rgba(0,0,0,0.15);
}

.cell-cam {
  position: absolute;
  bottom: 5px;
  right: 7px;
  font-size: 0.8rem;
  opacity: 0.5;
}

/* stats cell content */
.cell-count {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--green-dark);
  line-height: 1;
}

.cell-unit {
  font-size: 0.7rem;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cell-gallery-hint {
  font-size: 0.62rem;
  color: var(--green-dark);
  opacity: 0.7;
}

/* ── Top Nav ── */
.top-nav {
  height: var(--nav-h);
  display: flex;
  background: #fff;
  border-bottom: 2px solid #e0e0e0;
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: #999;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  transition: color 0.15s;
}

.nav-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  transition: background 0.15s;
}

.nav-btn.active             { color: var(--green-mid); }
.nav-btn.active::after      { background: var(--green-mid); }
.nav-btn svg                { display: block; }

/* ── Loading ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #fff;
  font-size: 0.9rem;
  z-index: 500;
}
.loading-overlay.hidden { display: none; }

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 10px 22px;
  border-radius: 22px;
  font-size: 0.85rem;
  white-space: nowrap;
  z-index: 400;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s;
}
.toast.hidden { opacity: 0; }

/* ── Gallery ── */
.gallery-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding-bottom: 4px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--green-mid);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

#gallery-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}

.gallery-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  display: block;
}

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: #888;
  padding: 48px 20px;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
}
.lightbox.hidden { display: none; }

.lightbox img {
  max-width: 96vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 4px;
}

#lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Unsure button (classify view) ── */
.unsure-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 16px;
  margin-top: 4px;
  background: #fafafa;
  border: 2px dashed #bbb;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s;
}
.unsure-btn:active { background: #f0f0f0; border-color: #999; }

.unsure-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ddd;
  color: #555;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

/* ── Unsure stats bar (stats view) ── */
.unsure-stats-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin-top: 4px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.unsure-stats-bar:active { background: #ebebeb; }

.unsure-stats-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  flex: 1;
}

.unsure-count {
  font-size: 1.6rem;
  font-weight: 800;
  color: #555;
  line-height: 1;
}

.unsure-unit {
  font-size: 0.7rem;
  font-weight: 600;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.unsure-hint {
  font-size: 0.65rem;
  color: #999;
  margin-left: 4px;
}

/* ── How-to instructions ── */
.how-to {
  list-style: none;
  counter-reset: step;
  padding: 10px 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.how-to li {
  counter-increment: step;
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 0.78rem;
  color: #555;
  line-height: 1.4;
}

.how-to li::before {
  content: counter(step);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--green-mid);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.how-to strong { color: #333; }
