/* ==========================================================================
   Neo-brutalist design system
   Ported from Views/Components/NeoBrutalistStyle.swift
   ========================================================================== */

:root {
  /* NeoColor */
  --ink: #0d0d0d;
  --paper: #f7ffee;
  --green-button: #6ead6b;
  --lime: #c4f000;
  --orange: #ff4d00;
  --blue: #2b50ff;
  --pink: #ff2e88;
  --cyan: #16e0e0;
  --yellow: #ffde59;
  --card: #ffffff;

  --radius-sm: 0;
  --radius-md: 0;
  --radius-lg: 0;

  --border: 3px;
  --border-thin: 2px;

  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;

  /* Minimum comfortable touch target. */
  --tap: 44px;

  /* The app is intentionally light-only; ink-on-paper is the whole idea. */
  color-scheme: light;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

html {
  /* Stops iOS from silently inflating text in landscape. */
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font-family: inherit;
  /* < 16px makes iOS Safari zoom the viewport on focus. */
  font-size: 16px;
  color: var(--ink);
}

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

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: var(--border) solid var(--blue);
  outline-offset: 2px;
}

/* The `hidden` attribute has to beat component display rules — .neo-btn is
   inline-flex, which would otherwise keep a hidden button on screen. */
[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

.app {
  /* Comfortable on a phone, centred and capped on a tablet or desktop. */
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

.row-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Horizontally scrolling filter/category rails. */
.rail {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 16px;
  margin: 0 -16px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.rail::-webkit-scrollbar {
  display: none;
}

.rail > * {
  flex: 0 0 auto;
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */

.mono {
  font-family: var(--font-mono);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.title-xl {
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: clamp(1.5rem, 7vw, 2.125rem);
  line-height: 1.1;
  margin: 0;
}

.title-lg {
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: clamp(1.25rem, 5.5vw, 1.625rem);
  line-height: 1.15;
  margin: 0;
}

.title-md {
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 1.0625rem;
  margin: 0;
}

.label {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.body {
  font-size: 0.9375rem;
  font-weight: 500;
  color: color-mix(in srgb, var(--ink) 85%, transparent);
  margin: 0;
}

.muted {
  color: color-mix(in srgb, var(--ink) 55%, transparent);
  font-size: 0.9375rem;
}

.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.struck {
  text-decoration: line-through;
  color: color-mix(in srgb, var(--ink) 50%, transparent);
}

/* --------------------------------------------------------------------------
   Card — NeoBrutalistCardModifier
   -------------------------------------------------------------------------- */

.neo-card {
  background: var(--card);
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.neo-card--tight {
  padding: 12px;
}

/* --------------------------------------------------------------------------
   Button — NeoBrutalistButtonStyle (flat: no offset shadow, square corners)
   -------------------------------------------------------------------------- */

.neo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 12px 16px;
  background: var(--yellow);
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 0.9375rem;
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  transition: box-shadow 90ms ease-out, filter 280ms ease-out;
}

/* Hover thickens the border; pressing snaps it back. A spread shadow is used
   instead of border-width so the button doesn't grow and nudge the layout.
   Hover is gated so touch devices don't get a sticky "hovered" state. */
@media (hover: hover) {
  .neo-btn:hover:not(:disabled),
  button.chip:hover {
    box-shadow: 0 0 0 2px var(--ink);
  }
}

.neo-btn:active:not(:disabled),
button.chip:active {
  box-shadow: none;
}

/* Press feedback: darken instantly on touch, then fade back on release (the
   base rule's filter transition handles the fade). A quick tap on a phone
   holds :active for only a few frames, so the fade is what makes it visible. */
.neo-btn:active:not(:disabled),
button.chip:active,
.icon-btn:active {
  filter: brightness(0.8);
  transition-duration: 0s;
}

.neo-btn:disabled {
  background: color-mix(in srgb, var(--ink) 20%, transparent);
  cursor: not-allowed;
}

.neo-btn--sm {
  min-height: 36px;
  padding: 8px 12px;
  font-size: 0.75rem;
  border-width: var(--border-thin);
  border-radius: var(--radius-md);
}

.neo-btn--block {
  width: 100%;
}

/* Icon-only square button — keeps the 44px target without stretching. */
.neo-btn--icon {
  min-width: var(--tap);
  padding: 8px;
  font-size: 1.125rem;
}

.neo-btn--lime { background: var(--lime); }
.neo-btn--yellow { background: var(--yellow); }
.neo-btn--cyan { background: var(--cyan); }
.neo-btn--white { background: var(--card); }
.neo-btn--orange { background: var(--orange); color: #fff; }
.neo-btn--pink { background: var(--pink); color: #fff; }
.neo-btn--green { background: var(--green-button); color: #fff; }

/* --------------------------------------------------------------------------
   Chip / badge — CategoryBadgeView, StatChip
   -------------------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 36px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.75rem;
  text-transform: uppercase;
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-md);
  transition: box-shadow 90ms ease-out, filter 280ms ease-out;
  white-space: nowrap;
}

.chip[aria-pressed="true"],
.chip--selected {
  background: var(--lime);
}

.chip--favorite[aria-pressed="true"] {
  background: var(--pink);
  color: #fff;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.6875rem;
  text-transform: uppercase;
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--cyan);
  white-space: nowrap;
}

.tag--yellow { background: var(--yellow); }
.tag--lime { background: var(--lime); }
.tag--orange { background: var(--orange); color: #fff; }

/* Section header pill in the form ("1. BASIC INFORMATION"). */
.section-tag {
  display: inline-flex;
  padding: 5px 9px;
  background: var(--blue);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.neo-input,
.neo-textarea,
.neo-select {
  width: 100%;
  padding: 11px;
  background: var(--paper);
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-md);
  font-size: 16px;
  appearance: none;
}

.neo-input:focus,
.neo-textarea:focus,
.neo-select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.neo-input--mono {
  font-family: var(--font-mono);
  font-weight: 700;
}

.neo-textarea {
  resize: vertical;
  min-height: 76px;
  line-height: 1.45;
}

.neo-select {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.875rem;
  padding: 9px 26px 9px 9px;
  min-height: 40px;
  /* Chevron drawn inline so we don't ship an asset for it. */
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%230d0d0d' stroke-width='2.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-size: 14px;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 0 12px;
}

.search-bar input {
  flex: 1 1 auto;
  border: none;
  outline: none;
  background: transparent;
  padding: 13px 0;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  min-width: 0;
}

.search-bar input::placeholder {
  color: color-mix(in srgb, var(--ink) 45%, transparent);
}

.search-clear {
  border: none;
  background: transparent;
  font-size: 1.125rem;
  line-height: 1;
  padding: 8px;
  margin-right: -4px;
}

/* Switch — Toggle(isOn:) with .tint(NeoColor.pink) */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  flex: 0 0 auto;
  width: 52px;
  height: 30px;
  border: var(--border-thin) solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  position: relative;
  transition: background 120ms ease-out;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--ink);
  transition: transform 120ms ease-out;
}

.switch input:checked + .switch-track {
  background: var(--pink);
}

.switch input:checked + .switch-track::after {
  transform: translateX(22px);
  background: var(--card);
}

.switch input:focus-visible + .switch-track {
  outline: var(--border) solid var(--blue);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Checklist rows — ingredients & instruction steps
   -------------------------------------------------------------------------- */

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px;
  background: var(--card);
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-md);
}

.check-row--done {
  background: var(--paper);
}

.check-box {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 1rem;
  line-height: 1;
}

.check-box--done {
  background: var(--lime);
}

.step-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px;
  background: var(--card);
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-md);
}

.step-row--done {
  background: var(--paper);
}

/* --------------------------------------------------------------------------
   Progress bar — CookingModeView
   -------------------------------------------------------------------------- */

.progress-track {
  height: 16px;
  background: var(--card);
  border: var(--border-thin) solid var(--ink);
  position: relative;
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--lime);
  border-right: var(--border-thin) solid var(--ink);
  transition: width 250ms cubic-bezier(0.34, 1.4, 0.64, 1);
}

/* --------------------------------------------------------------------------
   Screens & overlays
   -------------------------------------------------------------------------- */

/* Full-screen sheet standing in for .sheet / .fullScreenCover. */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: var(--border) solid var(--ink);
  flex: 0 0 auto;
}

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sheet-footer {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: var(--border) solid var(--ink);
}

.sheet-footer > * {
  flex: 1 1 0;
}

/* Empty state — NeoEmptyStateView */
.empty-state {
  text-align: center;
  background: var(--cyan);
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 24px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-state-emoji {
  font-size: 44px;
  line-height: 1;
}

/* Modal confirm — .alert(...) */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  display: grid;
  place-items: center;
  padding: 24px;
}

.dialog {
  background: var(--card);
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.dialog-actions > * {
  flex: 1 1 0;
}

/* Toast for sync/import feedback. */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.8125rem;
  border-radius: var(--radius-md);
}

.toast--error {
  background: var(--orange);
  color: #fff;
}

/* Skeleton shown while the first fetch is in flight. */
.skeleton {
  height: 104px;
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  background: linear-gradient(
    100deg,
    var(--card) 30%,
    var(--paper) 50%,
    var(--card) 70%
  );
  background-size: 220% 100%;
  animation: shimmer 1.1s linear infinite;
}

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -20% 0; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   Recipe card — "stretched link" so the whole card is tappable while the
   favourite button stays a separate control (valid HTML, no nested <a>/<button>)
   -------------------------------------------------------------------------- */

.recipe-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-link {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: var(--radius-lg);
  background: transparent;
  transition: background 280ms ease-out;
}

/* The stretched link's overlay covers the whole card, so tinting it darkens
   the card on press — same darken-then-fade as .neo-btn. */
.card-link:active::after {
  background: color-mix(in srgb, var(--ink) 15%, transparent);
  transition-duration: 0s;
}

.card-link:focus-visible::after {
  outline: var(--border) solid var(--blue);
  outline-offset: 2px;
}

.card-fav {
  position: relative;
  z-index: 2;
  min-width: 40px;
  justify-content: center;
  font-size: 1rem;
}

/* --------------------------------------------------------------------------
   Ingredient editor row (form section 2)
   -------------------------------------------------------------------------- */

.ingredient-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--paper) 60%, var(--card));
  border: var(--border-thin) solid var(--ink);
  border-radius: var(--radius-md);
}

.measure-row {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr) minmax(0, 1.4fr) auto;
  gap: 6px;
  align-items: center;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--pink);
  font-size: 1.0625rem;
  transition: filter 280ms ease-out;
}

.icon-btn:active {
  transform: scale(0.9);
}

/* --------------------------------------------------------------------------
   Cooking mode
   -------------------------------------------------------------------------- */

.cook-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
  padding: 28px;
}

.cook-step-text {
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.55;
  margin: 0;
}

.cook-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding: 16px;
}

/* --------------------------------------------------------------------------
   Paste-text import — one row per pasted line, each with a label picker
   -------------------------------------------------------------------------- */

.error-text {
  color: var(--orange);
}

.paste-text {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  min-height: 180px;
  /* Pasted recipes are line-oriented; wrapping hides where lines break. */
  white-space: pre;
  overflow-x: auto;
}

.line-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.line-row {
  display: grid;
  grid-template-columns: 7.25rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 5px;
  background: var(--card);
  border: var(--border-thin) solid var(--ink);
}

.line-text {
  font-size: 0.875rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.line-row--ignored .line-text {
  color: color-mix(in srgb, var(--ink) 45%, transparent);
  text-decoration: line-through;
}

/* A guess worth a second look: orange edge plus a "?" badge. */
.line-unsure {
  visibility: hidden;
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  background: var(--orange);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 900;
  font-size: 0.75rem;
  border: var(--border-thin) solid var(--ink);
}

.line-row--unsure {
  box-shadow: inset 5px 0 0 var(--orange);
  padding-left: 10px;
}

.line-row--unsure .line-unsure {
  visibility: visible;
}

/* The picker is the label: coloured by what it's set to. */
.line-label {
  min-height: 32px;
  padding: 5px 22px 5px 6px;
  font-size: 0.625rem;
  background-position: right 5px center;
  background-size: 12px;
  background-color: var(--card);
}

.line-label--title { background-color: var(--pink); color: #fff; }
.line-label--summary { background-color: var(--cyan); }
.line-label--ingredient { background-color: var(--lime); }
.line-label--step { background-color: var(--yellow); }
.line-label--prep_time,
.line-label--cook_time,
.line-label--servings { background-color: color-mix(in srgb, var(--blue) 25%, var(--card)); }
.line-label--ignore { background-color: var(--paper); }

/* Very narrow screens: label above the text instead of beside it. */
@media (max-width: 340px) {
  .line-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .line-label {
    grid-column: 1;
    justify-self: start;
    width: auto;
  }
  .line-unsure {
    grid-column: 2;
    grid-row: 1;
  }
  .line-text {
    grid-column: 1 / -1;
  }
}
