:root {
  color-scheme: light;

  /* Warm neutrals (tinted, never pure black/white) */
  --bg: oklch(97% 0.007 60);
  --surface: oklch(99% 0.003 60);
  --surface-2: oklch(94.5% 0.009 60);
  --border: oklch(88% 0.013 55);
  --border-strong: oklch(78% 0.02 50);
  --text: oklch(24% 0.014 45);
  --text-muted: oklch(48% 0.018 45);
  --text-faint: oklch(62% 0.015 45);

  /* Accent: warm terracotta, carries primary actions + selection state */
  --accent: oklch(58% 0.16 35);
  --accent-hover: oklch(53% 0.16 35);
  --accent-active: oklch(48% 0.16 35);
  --accent-soft: oklch(93% 0.035 40);
  --accent-soft-text: oklch(40% 0.11 35);
  --accent-contrast: oklch(99% 0.005 60);

  /* Semantic */
  --success: oklch(56% 0.13 152);
  --success-soft: oklch(93% 0.045 152);
  --success-soft-text: oklch(38% 0.09 152);
  --warning-soft: oklch(93% 0.05 80);
  --warning-soft-text: oklch(42% 0.09 65);
  --danger: oklch(55% 0.19 25);
  --danger-hover: oklch(49% 0.19 25);
  --danger-soft: oklch(93% 0.04 25);
  --danger-soft-text: oklch(42% 0.14 25);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px oklch(30% 0.02 50 / 0.06), 0 1px 1px oklch(30% 0.02 50 / 0.04);
  --shadow-md: 0 8px 24px oklch(30% 0.03 50 / 0.10), 0 2px 6px oklch(30% 0.03 50 / 0.06);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  padding: 20px 16px 48px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 760px;
  margin: 0 auto;
}

h1, h2 {
  line-height: 1.2;
}

/* --- Header --- */

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

#app-title {
  margin: 0;
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.7rem);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.lang-field {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.lang-field-icon {
  position: absolute;
  left: 10px;
  font-size: 14px;
  pointer-events: none;
}

#lang-select {
  appearance: none;
  padding: 9px 30px 9px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23767066' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text);
  cursor: pointer;
  transition: border-color 160ms var(--ease-out);
}

#lang-select:hover {
  border-color: var(--border-strong);
}

/* --- Tabs (segmented control) --- */

#tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 24px;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
}

.tab-btn {
  flex: 1;
  min-height: 44px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fade-in 200ms var(--ease-out);
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

h2 {
  margin: 4px 0 4px;
  font-size: 1.2rem;
  font-weight: 700;
}

#chores-intro {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* --- Forms --- */

form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

@media (min-width: 640px) {
  form {
    flex-direction: row;
  }
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}

input[type="text"]::placeholder {
  color: var(--text-faint);
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.kid-name-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

input[type="color"] {
  width: 46px;
  height: 46px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  flex: 0 0 auto;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 7px;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

#chore-title {
  flex: 1;
}

#chore-prompt {
  flex: 2;
}

/* --- Buttons --- */

button {
  min-height: 46px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 150ms var(--ease-out), transform 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}

button:hover {
  background: var(--accent-hover);
}

button:active {
  background: var(--accent-active);
  transform: scale(0.98);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
  cursor: not-allowed;
  transform: none;
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
}

.secondary-btn:hover {
  background: var(--border);
}

.secondary-btn:active {
  background: var(--border-strong);
}

/* --- Kids list --- */

#kid-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 0;
}

#kid-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
  font-size: 14px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px oklch(0% 0 0 / 0.08);
}

#kid-list .remove-btn {
  min-height: 30px;
  width: 30px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  font-size: 0;
  line-height: 1;
  position: relative;
}

#kid-list .remove-btn::before {
  content: "✕";
  font-size: 13px;
}

#kid-list .remove-btn:hover {
  background: var(--danger-soft);
  color: var(--danger-soft-text);
}

.empty-state {
  grid-column: 1 / -1;
  padding: 22px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

/* --- Print actions & status --- */

.print-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 14px;
}

.print-actions button {
  flex: 1 1 0;
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

#print-new-btn {
  flex-grow: 1.4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#print-new-btn .btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

#print-new-btn .btn-count {
  flex-shrink: 0;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: oklch(100% 0 0 / 0.28);
  font-size: 0.9em;
  font-weight: 700;
}

@media (min-width: 400px) {
  .print-actions button {
    font-size: 14px;
  }
}

@media (min-width: 480px) {
  .print-actions button {
    font-size: 15px;
    padding-left: 18px;
    padding-right: 18px;
  }
}

.generation-status {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
  background: var(--warning-soft);
  color: var(--warning-soft-text);
  font-size: 14px;
  font-weight: 500;
}

/* --- Print calibration (collapsible) --- */

.print-settings {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 4px 14px;
}

.print-settings summary {
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.print-settings[open] summary {
  color: var(--text);
}

.print-settings form {
  flex-direction: column;
  gap: 12px;
  margin: 4px 0 14px;
}

.print-settings label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.offset-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.print-settings input[type="number"] {
  width: 90px;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

.print-settings input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.offset-mm {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-faint);
  white-space: nowrap;
}

.settings-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.4;
}

.settings-note {
  margin: 2px 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* --- Chore grid & cards --- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

@media (min-width: 640px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
  }
}

.chore-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow 200ms var(--ease-out), transform 200ms var(--ease-out);
}

.chore-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.chore-visual {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: 128px;
  margin: 0 auto 10px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
}

.chore-visual::after {
  content: '⋯';
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: oklch(20% 0.02 45 / 0.55);
  color: white;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}

.chore-card.expanded .chore-visual::after {
  display: none;
}

.chore-card img,
.chore-card .emoji,
.chore-card .pending {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chore-card img {
  object-fit: cover;
}

.chore-card .emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
}

.chore-card .pending {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.chore-card .pending span {
  display: inline-block;
  animation: spin 1.6s linear infinite;
}

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

.chore-card .name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 6px;
  overflow-wrap: break-word;
}

.chore-card .badge {
  display: inline-flex;
  align-self: center;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  margin-bottom: 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

.chore-card .badge-new {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.chore-card .badge-printed {
  background: var(--success-soft);
  color: var(--success-soft-text);
}

.chore-card .actions {
  display: none;
  position: absolute;
  inset: 0;
  grid-template-columns: 1fr;
  align-content: center;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: oklch(20% 0.02 45 / 0.72);
  cursor: default;
}

.chore-card.expanded .actions {
  display: grid;
}

.chore-card .actions button {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chore-card .remove-btn {
  grid-column: 1 / -1;
  background: var(--danger-soft);
  color: var(--danger-soft-text);
}

.chore-card .remove-btn:hover {
  background: var(--danger);
  color: var(--accent-contrast);
}

.chore-card .edit-btn {
  background: var(--surface-2);
  color: var(--text);
}

.chore-card .edit-btn:hover {
  background: var(--border);
}

.chore-card .regen-btn {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.chore-card .regen-btn:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* --- Inline chore edit form --- */

.chore-card .edit-form {
  display: block;
  margin-bottom: 8px;
  text-align: left;
}

.chore-card .edit-title-input,
.chore-card .edit-prompt-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.chore-card .edit-title-input:focus,
.chore-card .edit-prompt-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chore-card .edit-prompt-input {
  font-size: 12px;
  color: var(--text-muted);
}

.chore-card .edit-actions {
  display: flex;
  gap: 6px;
}

.chore-card .edit-actions button {
  flex: 1;
  min-height: 36px;
  font-size: 13px;
}

.chore-card .cancel-edit-btn {
  background: var(--surface-2);
  color: var(--text);
}

.chore-card .cancel-edit-btn:hover {
  background: var(--border);
}

#app-footer {
  text-align: center;
  padding: 16px 0 24px;
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* --- Print area (screen placeholder only; @media print below is untouched) --- */

#print-area {
  display: none;
}

@page {
  margin: 0.5in;
}

/* Chrome's print/PDF pipeline renders page 1's content ~15pt (~0.21in)
   lower than every following page, even though every .print-sheet is
   identical and forced onto its own page. Measured directly against
   generated PDF output (not guessed): page 1's first card row sits at
   82.5pt from the page top, pages 2+ sit at 67.5pt. Shaving that same
   15pt off just the first page's top margin lines page 1 back up with
   the rest instead of sacrificing a page to work around it. */
@page :first {
  margin-top: 21pt;
}

@media print {
  #app,
  #app-footer {
    display: none;
  }

  #print-area {
    display: block;
  }

  /* One sheet = one physical page, sized to hold exactly one page's worth
     of cards (2 cols x 3 rows) so front/back sheets pair up 1:1 with the
     printer's duplex unit. Rows are deliberately shorter than the nominal
     usable page height, and padded top/bottom, so there's real slack no
     matter how a given print pipeline computes its printable area (desktop
     browsers and iOS/AirPrint handle @page margins very differently) —
     that slack is what keeps the card borders from landing in a printer's
     hardware-unprintable strip, without forcing an exact page height that
     could overflow into a stray extra page on some renderers. */
  .print-sheet {
    display: grid;
    grid-template-columns: repeat(2, 3.4in);
    grid-auto-rows: 2.5in;
    gap: 0.1in;
    justify-content: center;
    padding: 0.4in 0;
    page-break-after: always;
  }

  .print-card {
    border-style: solid;
    border-width: 8px;
    border-radius: 10px;
    box-sizing: border-box;
    padding: 0.1in;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    page-break-inside: avoid;
  }

  .print-card .kid-name {
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 6px;
    text-transform: uppercase;
  }

  .print-card img, .print-card .emoji {
    width: 1.5in;
    height: 1.5in;
    object-fit: cover;
    border-radius: 8px;
  }

  .print-card .emoji {
    font-size: 96px;
    line-height: 1.5in;
  }

  .print-card .chore-name {
    margin-top: 6px;
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
  }

  .print-card-back .chore-name {
    margin-top: 0;
  }

  .print-card-back .chore-desc {
    margin-top: 8px;
    font-size: 14px;
    font-weight: normal;
    text-transform: none;
    line-height: 1.4;
  }
}
