:root {
  --bg: #f4f0e8;
  --bg-deep: #e7e1d4;
  --ink: #241c16;
  --muted: #5e534a;
  --line: #e0d6c8;
  --card: #ffffff;
  --green: #0b5d4b;
  --green-dark: #084538;
  --warn: #8a4b08;
  --warn-soft: #fff3dc;
  --bad: #8d2b2b;
  --brown: #8a3d12;
  --olive: #5a430c;
  --shadow: 0 1px 2px rgba(36, 28, 22, 0.06);
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.35;
}

button, input, select { font: inherit; color: inherit; }

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

button:disabled { opacity: 0.35; cursor: default; }

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  box-shadow: 0 0 0 1px rgba(36, 28, 22, 0.05);
  overflow-x: hidden;
}

body.is-export .app { max-width: 1100px; }

.clip {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

.sticky-top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(244, 240, 232, 0.96);
  backdrop-filter: blur(8px);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}

.top { padding: 10px 16px 0; }

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--green-dark);
}

.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.lang {
  display: flex;
  background: #ebe4d8;
  border-radius: 999px;
  padding: 4px;
  flex: none;
}

.lang button {
  min-width: 56px;
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.lang button.is-on {
  background: white;
  color: var(--green-dark);
  box-shadow: var(--shadow);
}

.date-row {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}

.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: white;
  font-size: 1.8rem;
  line-height: 1;
  font-weight: 600;
  color: var(--green-dark);
}

.date-btn {
  min-height: 52px;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
}

.date-btn strong {
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
}

.pill {
  display: inline-block;
  background: var(--green);
  color: white;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.text-btn {
  display: block;
  width: calc(100% - 8px);
  margin: 4px auto 8px;
  min-height: 44px;
  border-radius: 12px;
  border: 2px solid var(--green);
  background: white;
  color: var(--green-dark);
  font-weight: 800;
}

.segments {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  padding: 4px 12px 10px;
}

.seg {
  position: relative;
  min-height: 64px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: white;
  padding: 8px 6px;
  font-weight: 800;
}

.seg small {
  display: block;
  margin-top: 2px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.2;
}

.seg.is-on {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.seg.is-on small { color: rgba(255, 255, 255, 0.88); }

.mark {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--green);
}

.seg.is-on .mark { background: white; }

main { padding: 12px 16px 8px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card h2, .card h3 {
  margin: 0 0 12px;
  font-size: 1.12rem;
  line-height: 1.25;
}

.field {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.choices.stack { grid-template-columns: 1fr; }

.choice {
  min-height: 64px;
  border-radius: 14px;
  border: 2px solid #ddd4c8;
  background: #fff;
  font-weight: 800;
  font-size: 1.08rem;
  padding: 10px 12px;
}

.choices.stack .choice { min-height: 60px; }

.choice.is-on {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.choice[data-value="restless"].is-on,
.choice[data-value="upset"].is-on,
.choice[data-value="no"].is-on {
  background: var(--brown);
  border-color: var(--brown);
}

.choice[data-value="low"].is-on,
.choice[data-value="little"].is-on {
  background: var(--olive);
  border-color: var(--olive);
  color: white;
}

.choice:active { transform: scale(0.99); }

.counter {
  display: grid;
  grid-template-columns: 76px 1fr 76px;
  gap: 10px;
  align-items: center;
}

.counter button {
  height: 76px;
  border-radius: 16px;
  border: 2px solid #ddd4c8;
  background: white;
  font-size: 2.2rem;
  line-height: 1;
  font-weight: 600;
  color: var(--green-dark);
}

.counter button:active { background: #f3faf7; }

.count-readout { text-align: center; }

.count-readout strong {
  display: block;
  font-size: 2.6rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.times {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
}

.stack-label { display: block; }

.stack-label > span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
  font-weight: 800;
}

input[type="time"],
input[type="date"],
input[type="text"],
input[inputmode="numeric"],
select {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 8px 12px;
  border: 2px solid #ddd4c8;
  border-radius: 14px;
  background: white;
  font-size: 1.2rem;
  font-weight: 700;
}

.bp-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: end;
}

.slash {
  padding-bottom: 14px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--muted);
}

.hint {
  margin: 10px 0 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.hint.warn { color: var(--warn); }
.hint.bad { color: var(--bad); }
.hint.center { text-align: center; padding: 0 16px 8px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-height: 64px;
  margin-top: 12px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
}

.check input {
  width: 32px;
  height: 32px;
  margin-top: 2px;
  flex: none;
  accent-color: var(--green);
}

.check small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.log-end {
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
}

.saved {
  margin: 0;
  padding: 0 16px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  min-height: 1.4em;
}

.saved.is-fresh { color: var(--green); }
.saved.is-bad { color: var(--bad); }

.primary, .secondary {
  min-height: 56px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 12px 16px;
}

.primary {
  width: 100%;
  border: 0;
  background: var(--green);
  color: white;
}

.primary:active { background: var(--green-dark); }

.secondary {
  width: 100%;
  border: 2px solid var(--green);
  background: white;
  color: var(--green-dark);
}

.secondary.is-on {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

.privacy {
  margin: 10px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
}

#export-view { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

.export-top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(244, 240, 232, 0.96);
  border-bottom: 1px solid var(--line);
}

.export-top h2 { margin: 0; font-size: 1.3rem; }

.export-controls { padding: 14px 16px 0; }

.lead {
  margin: 0 0 12px;
  color: var(--muted);
  font-weight: 700;
}

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

.mode button {
  min-height: 52px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: white;
  font-weight: 800;
}

.mode button.is-on {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.month-row, .range-row {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 10px;
}

.range-row { grid-template-columns: 1fr 1fr; }

#sample-btn { margin-top: 12px; }

.ui-summary {
  margin: 12px 0 0;
  font-weight: 800;
  text-align: center;
}

.sheet {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  margin: 14px 16px 16px;
  padding: 16px;
}

.sample-banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 900;
  letter-spacing: 0.01em;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.45rem;
  color: var(--green-dark);
}

.sheet-head p { margin: 4px 0 0; }

.sheet-sub { font-weight: 800; }

.sheet-meta { color: var(--muted); font-size: 0.92rem; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.chip {
  display: inline-block;
  border-radius: 999px;
  padding: 6px 10px;
  background: #f3f0ea;
  font-size: 0.92rem;
  font-weight: 800;
}

.chip.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.empty {
  margin: 8px 0 12px;
  font-weight: 700;
}

.swipe {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.sheet,
#export-view,
.table-scroll {
  max-width: 100%;
  min-width: 0;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
}

table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 0.92rem;
  background: white;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
  vertical-align: top;
}

th {
  background: var(--green-dark);
  color: white;
  font-size: 0.8rem;
  font-weight: 800;
  position: sticky;
  top: 0;
}

td:first-child, th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}

th:first-child { z-index: 2; background: var(--green-dark); }
td:first-child { background: white; font-weight: 800; }

tr.is-flagged td { background: #fff8ec; }
tr.is-flagged td:first-child { background: #fff1d6; }

.flag-cell { font-weight: 800; color: var(--warn); }

.footnote {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.share-box {
  margin: 8px 0 0;
  padding: 12px;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  background: white;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 0.85rem;
}

.noscript {
  max-width: 480px;
  margin: 16px auto;
  padding: 16px;
  background: white;
  font-weight: 700;
}

@media (max-width: 360px) {
  .seg small { display: none; }
  .brand h1 { font-size: 1.25rem; }
}

@media print {
  body { background: white; }
  .app {
    max-width: none;
    box-shadow: none;
    background: white;
    overflow: visible;
  }
  .no-print { display: none !important; }
  body.is-export #log-screen { display: none !important; }
  body.is-export #export-view { display: block !important; }
  .sheet {
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0;
  }
  .table-scroll { overflow: visible; border: 0; }
  table { width: 100%; font-size: 9px; }
  th, td {
    white-space: normal;
    padding: 3px 4px;
  }
  th {
    position: static;
    color: black;
    background: #e7f3ef !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  td:first-child, th:first-child { position: static; }
  tr.is-flagged td {
    background: #fff3d6 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  @page { size: A4 landscape; margin: 10mm; }
}
