:root {
  color-scheme: light dark;
  --bg: #f7f1e8;
  --surface: #fffdf9;
  --surface-2: #f2e7d8;
  --text: #2f2925;
  --muted: #6d625b;
  --border: #dfd2c3;
  --accent: #a64b2a;
  --accent-strong: #85391f;
  --accent-soft: #f3d7c8;
  --success: #376f4a;
  --danger: #a12f2f;
  --shadow: 0 10px 30px rgb(61 42 28 / 10%);
  --radius: 18px;
  --content-width: 920px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191512;
    --surface: #26201c;
    --surface-2: #342a24;
    --text: #f6eee7;
    --muted: #c7b8ac;
    --border: #493b32;
    --accent: #e48b65;
    --accent-strong: #f0a582;
    --accent-soft: #4b2e23;
    --success: #83c796;
    --danger: #ff9494;
    --shadow: 0 10px 30px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; }
a { color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }

.skip-link {
  position: fixed;
  top: -60px;
  left: 12px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: 10px;
}
.skip-link:focus { top: 12px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  min-height: 62px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 800;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: .8rem;
}
.connection-status {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: .78rem;
  font-weight: 750;
}

.app-main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 22px 18px 40px;
}
.app-main:focus {
  outline: none;
}
.page-header { margin-bottom: 20px; }
.page-header h1 { margin: 0 0 6px; font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.1; }
.page-header p { margin: 0; color: var(--muted); }

.hero {
  padding: 24px;
  border-radius: 24px;
  background: linear-gradient(145deg, var(--accent-soft), var(--surface));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.hero h1 { margin: 0 0 8px; font-size: clamp(2rem, 8vw, 3.4rem); line-height: 1; }
.hero p { margin: 0 0 18px; color: var(--muted); max-width: 54ch; }

.search-row { display: flex; gap: 10px; }
.search-field {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 14px;
}
.search-field:focus, input:focus, textarea:focus, select:focus {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-color: var(--accent);
}

.section { margin: 28px 0; }
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-heading h2 { margin: 0; font-size: 1.25rem; }
.section-heading a { color: var(--accent); font-weight: 700; text-decoration: none; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.card, .category-card, .panel, .loading-card, .empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 178px;
  padding: 18px;
  text-decoration: none;
}
.card:hover, .category-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card h3 { margin: 0 34px 6px 0; line-height: 1.2; }
.card p { margin: 0 0 14px; color: var(--muted); }
.card-meta { margin-top: auto; display: flex; flex-wrap: wrap; gap: 7px; }
.origin-badge, .tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .78rem;
}
.favorite-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
}
.favorite-button:hover { background: var(--accent-soft); }
.category-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 122px;
  padding: 16px;
  text-decoration: none;
  transition: .15s ease;
}
.category-icon { font-size: 1.8rem; }
.category-card strong { font-size: 1.02rem; }
.category-card small { color: var(--muted); }

.panel { padding: 20px; margin-bottom: 16px; }
.panel h2, .panel h3 { margin-top: 0; }
.empty-state, .loading-card { padding: 28px; text-align: center; color: var(--muted); }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
  cursor: pointer;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.button.danger { color: var(--danger); }
.button:disabled { opacity: .55; cursor: not-allowed; }

.recipe-header { margin-bottom: 18px; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--accent); text-decoration: none; font-weight: 700; }
.recipe-title-row { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.recipe-title-row h1 { margin: 0; font-size: clamp(2rem, 7vw, 3.2rem); line-height: 1.05; }
.recipe-description { color: var(--muted); font-size: 1.05rem; max-width: 65ch; }
.recipe-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.recipe-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.panel-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; margin-bottom:12px; }
.panel-heading h2 { margin:0; }
.ingredients-list { list-style: none; padding: 0; margin: 0; }
.ingredients-list li {
  display: grid;
  grid-template-columns: minmax(72px, auto) 1fr;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.ingredient-amount { font-weight: 800; }
.steps-list { padding-left: 1.4rem; }
.steps-list li { margin-bottom: 14px; padding-left: 5px; }
.notes-box { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 14px 16px; border-radius: 0 12px 12px 0; }

.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; }
.field label { font-weight: 750; }
.field small { color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
}
.field textarea { min-height: 96px; resize: vertical; }
.repeater { display: grid; gap: 10px; }
.repeater-row {
  display: grid;
  grid-template-columns: 110px 100px minmax(140px, 1fr) 44px;
  gap: 8px;
  align-items: center;
}
.step-row { grid-template-columns: 1fr 44px; }
.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--danger);
  cursor: pointer;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px max(8px, env(safe-area-inset-left)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  min-height: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
}
.bottom-nav a > span:first-child { font-size: 1.35rem; line-height: 1; }
.bottom-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translateX(-50%);
  width: min(90vw, 430px);
  padding: 12px 15px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 700;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

@media (max-width: 650px) {
  .app-main { padding-inline: 14px; }
  .hero { padding: 20px; }
  .form-grid.two { grid-template-columns: 1fr; }
  .repeater-row { grid-template-columns: 82px 74px 1fr 42px; }
  .recipe-title-row { display: block; }
  .recipe-title-row .favorite-button { position: static; margin-top: 10px; }
}

@media print {
  body { background: white; color: black; padding: 0; }
  .app-header, .bottom-nav, .recipe-actions, .back-link, .favorite-button { display: none !important; }
  .app-main { max-width: none; padding: 0; }
  .panel { border: 0; box-shadow: none; padding: 0; break-inside: avoid; }
}

/* v0.2.0 */
.scale-controls { display: flex; align-items: center; gap: 9px; margin: 10px 0 14px; }
.scale-controls label { font-weight: 750; }
.scale-controls select { min-height: 40px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); }
.validation-report { margin-top: 16px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border); }
.validation-report.error { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.validation-report.success { border-color: var(--success); background: color-mix(in srgb, var(--success) 8%, var(--surface)); }
.validation-report ul { margin-bottom: 0; }
.category-manager { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.category-form { display: grid; grid-template-columns: 70px minmax(150px, 1fr) auto; gap: 8px; }
.category-form input { min-height: 44px; border: 1px solid var(--border); border-radius: 11px; padding: 9px 11px; background: var(--surface); color: var(--text); }
.category-list { list-style: none; padding: 0; margin: 14px 0 0; }
.category-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.muted { color: var(--muted); }
.repeater-row { grid-template-columns: 28px 110px 100px minmax(140px, 1fr) 44px; }
.step-row { grid-template-columns: 28px 1fr 44px; }
.drag-handle { cursor: grab; color: var(--muted); font-weight: 900; text-align: center; user-select: none; }
.repeater-row.dragging { opacity: .45; }
.repeater-row > input[style*="grid-column"] { grid-column: 2 / -1 !important; }
@media (max-width: 650px) {
  .category-form { grid-template-columns: 60px 1fr; }
  .category-form .button { grid-column: 1 / -1; }
  .repeater-row { grid-template-columns: 24px 78px 70px 1fr 42px; }
  .step-row { grid-template-columns: 24px 1fr 42px; }
}

.yield-controller {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  align-items: center;
  gap: 12px 18px;
  margin: 18px 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.yield-controller h2 { margin: 0 0 3px; font-size: 1.05rem; }
.yield-controller p { margin: 0; color: var(--muted); }
.yield-counter { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.yield-counter button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  font-size: 1.45rem;
  font-weight: 800;
  cursor: pointer;
}
.yield-counter input {
  width: 92px;
  height: 46px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  font-size: 1.15rem;
  font-weight: 800;
}
.yield-unit { min-width: 90px; font-weight: 750; }
.scale-status {
  min-height: 24px;
  color: var(--accent-strong);
  font-weight: 750;
}
.reset-scale { justify-self: end; }

@media (max-width: 600px) {
  .yield-controller { grid-template-columns: 1fr; }
  .yield-counter { justify-content: flex-start; }
  .reset-scale { justify-self: start; }
}

@media print {
  .yield-counter button, .reset-scale { display: none !important; }
  .yield-counter input { border: 0; background: transparent; width: auto; }
}


/* v0.6.0 – illustrert fremgangsmåte */
.instruction-panel .muted { margin-top: -.35rem; }
.instruction-dialog {
  width: min(96vw, 1120px);
  height: min(94vh, 1000px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgb(0 0 0 / 40%);
}
.instruction-dialog::backdrop { background: rgb(0 0 0 / 72%); }
.instruction-dialog[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.instruction-dialog-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--border);
}
.instruction-dialog-header h2 { margin: 0; }
.instruction-dialog-header p { margin: 3px 0 0; }
.instruction-dialog-close { flex: 0 0 auto; font-size: 1.6rem; }
.instruction-toolbar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.instruction-toolbar .button { min-width: 54px; min-height: 40px; padding-block: 7px; }
.instruction-image-viewport {
  overflow: auto;
  padding: 14px;
  background: #171717;
  overscroll-behavior: contain;
}
.instruction-dialog-image {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0 auto;
  border-radius: 6px;
  transform-origin: top center;
}
@media (max-width: 650px) {
  .instruction-dialog { width: 100vw; height: 100dvh; max-width: none; max-height: none; border: 0; border-radius: 0; }
  .instruction-dialog-header { padding-top: calc(12px + env(safe-area-inset-top)); }
  .instruction-image-viewport { padding: 8px; }
}
@media print {
  .instruction-panel, .instruction-dialog { display: none !important; }
}

/* v0.7.0 - Kokkemodus */
.cook-toolbar {
  position: sticky;
  top: 10px;
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.cook-toolbar[hidden] { display: none !important; }
.cook-toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cook-toolbar .button { min-height: 40px; padding: 8px 12px; }
.cook-wake-status { flex-basis: 100%; color: var(--muted); font-size: .86rem; }

body.cook-mode {
  padding-bottom: 24px;
  font-size: calc(1rem * var(--cook-font-scale, 1));
}
body.cook-mode .app-header,
body.cook-mode .bottom-nav,
body.cook-mode .back-link,
body.cook-mode .recipe-description,
body.cook-mode .recipe-meta,
body.cook-mode .recipe-actions,
body.cook-mode .favorite-button,
body.cook-mode .cook-secondary-panel,
body.cook-mode .credits-panel,
body.cook-mode .panel-heading .button-row {
  display: none !important;
}
body.cook-mode .app-main {
  max-width: 1100px;
  padding-top: 10px;
}
body.cook-mode .recipe-header { margin-bottom: 12px; }
body.cook-mode .recipe-title-row h1 {
  font-size: clamp(2.1rem, 7vw, 4rem);
}
body.cook-mode .yield-controller,
body.cook-mode .cook-content-panel {
  border-width: 2px;
  box-shadow: none;
}
body.cook-mode .ingredients-list li {
  padding-block: .85em;
  grid-template-columns: minmax(6.5em, auto) 1fr;
}
body.cook-mode .steps-list li {
  margin-bottom: 1.15em;
  line-height: 1.65;
}
body.cook-mode .instruction-image-button { font-size: 1em; }

@media (max-width: 650px) {
  .cook-toolbar { top: 6px; }
  .cook-toolbar > strong { width: 100%; }
  .cook-toolbar-actions { width: 100%; }
  .cook-toolbar-actions .button { flex: 1; }
  body.cook-mode .app-main { padding-inline: 10px; }
  body.cook-mode .panel { padding: 16px; }
}
.instruction-dialog img,
.instruction-dialog object,
.instruction-dialog svg {
    background: white;
}
/* v0.8.0 - Avkryssing av fremgangsmåte */
.steps-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}
.steps-heading h2 { margin-bottom: 4px; }
.steps-heading p { margin: 0; }
.steps-list { padding-left: 2.3rem; }
.step-item { margin-bottom: .7rem; }
.step-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: .65rem;
  align-items: start;
  min-height: 48px;
  padding: .72rem .8rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1.55;
  text-align: left;
  cursor: pointer;
}
.step-toggle:hover { background: var(--surface-2); }
.step-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.step-toggle:disabled { cursor: wait; opacity: .72; }
.step-marker {
  display: inline-grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  margin-top: .02rem;
  border: 2px solid var(--border);
  border-radius: 50%;
  font-weight: 900;
  line-height: 1;
}
.step-item.completed .step-toggle { background: color-mix(in srgb, var(--success) 8%, var(--surface)); }
.step-item.completed .step-marker { border-color: var(--success); color: var(--success); }
.step-item.completed .step-text { color: var(--muted); text-decoration: line-through; text-decoration-thickness: .08em; }

body.cook-mode .steps-heading { align-items: center; }
body.cook-mode .steps-list { padding-left: 2.5rem; }
body.cook-mode .steps-list li { margin-bottom: .85em; line-height: inherit; }
body.cook-mode .step-toggle {
  min-height: 62px;
  padding: .9em .95em;
  border-color: var(--border);
  border-radius: 14px;
  line-height: 1.65;
}
body.cook-mode .step-marker { width: 2em; height: 2em; }
body.cook-mode .step-item.completed .step-toggle { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); }

@media (max-width: 650px) {
  .steps-heading { display: grid; grid-template-columns: 1fr; }
  .steps-heading .button { justify-self: start; }
  .steps-list { padding-left: 1.8rem; }
  .step-toggle { grid-template-columns: 1.9rem 1fr; padding-inline: .55rem; }
}

@media print {
  .steps-heading .button, .step-marker { display: none !important; }
  .step-toggle { display: block; min-height: 0; padding: 0; border: 0; background: transparent !important; }
  .step-item.completed .step-text { color: inherit; text-decoration: none; }
}
