:root {
  color-scheme: light;
  --bg: #f8faf7;
  --surface: #ffffff;
  --surface-2: #f1f6f4;
  --ink: #18211d;
  --muted: #66736d;
  --line: #dfe8e3;
  --green: #24745a;
  --green-2: #e4f3ed;
  --red: #b94b4b;
  --red-2: #fae7e3;
  --blue: #2e6d9f;
  --blue-2: #e4f0f8;
  --gold: #8a651e;
  --gold-2: #f6edcf;
  --shadow: 0 16px 48px rgba(27, 39, 33, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 247, 0.92);
  backdrop-filter: blur(18px);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 18px;
  gap: 14px;
}

.brand {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.install-btn {
  min-height: 34px;
  padding: 6px 10px;
  color: var(--green);
  border-color: #b9d8cb;
  background: var(--green-2);
}

.mode-pill,
.status-pill,
.tag,
.category-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.mode-pill.admin {
  border-color: #d8c37a;
  background: var(--gold-2);
  color: var(--gold);
}

.main {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 18px calc(106px + env(safe-area-inset-bottom));
  min-width: 0;
}

.nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

.nav-inner {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
}

.nav button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.nav button.active {
  background: var(--green-2);
  color: var(--green);
  font-weight: 700;
}

.toolbar,
.section-head,
.record-head,
.card-head,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toolbar {
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.section-head {
  margin: 10px 0 14px;
}

.section-title {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0;
}

.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  min-width: 0;
}

.dish-card,
.record-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 24px rgba(27, 39, 33, 0.05);
}

.dish-card {
  min-height: 176px;
  padding: 14px;
}

.dish-card.disabled {
  background: #f5f6f5;
  color: var(--muted);
}

.dish-card.selected {
  border-color: #86b9a6;
  background: #f4fbf8;
}

.dish-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.dish-meta,
.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.tag {
  min-height: 24px;
  padding: 3px 8px;
  font-size: 12px;
}

.tag.green {
  border-color: #b9d8cb;
  background: var(--green-2);
  color: var(--green);
}

.tag.blue {
  border-color: #bad5e7;
  background: var(--blue-2);
  color: var(--blue);
}

.tag.red {
  border-color: #edc0ba;
  background: var(--red-2);
  color: var(--red);
}

.dish-summary {
  min-height: 44px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.category-strip {
  display: flex;
  gap: 8px;
  max-width: 100%;
  margin: 0 0 14px;
  padding: 2px 0 8px;
  overflow-x: auto;
}

.category-chip {
  border-radius: 8px;
  border-color: var(--line);
}

.category-chip.active {
  border-color: #86b9a6;
  background: var(--green-2);
  color: var(--green);
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 13px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: #aacabd;
}

.btn.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.btn.blue {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.btn.danger {
  border-color: #e1b3ad;
  background: var(--red-2);
  color: var(--red);
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.field,
.field-row {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: var(--surface);
  color: var(--ink);
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.selection-bar {
  position: sticky;
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  border: 1px solid #c7dcd3;
  border-radius: 8px;
  padding: 12px;
  background: #f3fbf7;
  box-shadow: var(--shadow);
}

.selection-fields {
  display: grid;
  grid-template-columns: minmax(110px, 180px) 1fr;
  gap: 8px;
}

.selection-summary {
  color: var(--green);
  font-weight: 700;
}

.login-shell {
  display: grid;
  min-height: min(520px, calc(100vh - 180px));
  place-items: center;
}

.login-panel {
  display: grid;
  gap: 16px;
  width: min(380px, 100%);
}

.random-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}

.counter {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.counter-controls {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  align-items: center;
  gap: 8px;
}

.counter-controls button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.counter-controls input {
  min-width: 0;
  text-align: center;
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

.record-list {
  display: grid;
  gap: 12px;
}

.record-card {
  padding: 14px;
}

.record-items {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.empty,
.boot {
  border: 1px dashed #cddbd4;
  border-radius: 8px;
  padding: 28px 16px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  text-align: center;
}

.notice {
  margin-bottom: 14px;
  border: 1px solid #c9ddcf;
  border-radius: 8px;
  padding: 11px 12px;
  background: #eef9f0;
  color: #2f6848;
}

.notice.error {
  border-color: #ecc0b9;
  background: var(--red-2);
  color: var(--red);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 31, 27, 0.42);
}

.modal {
  width: min(760px, 100%);
  max-height: min(88vh, 920px);
  overflow: auto;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
  position: sticky;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
}

.modal-header {
  top: 0;
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  bottom: 0;
  border-top: 1px solid var(--line);
}

.modal-body {
  padding: 16px;
}

.recipe-block {
  display: grid;
  gap: 12px;
}

.recipe-block h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.recipe-block p,
.recipe-block li {
  color: var(--muted);
  line-height: 1.65;
}

.recipe-block ol,
.recipe-block ul {
  margin: 0;
  padding-left: 22px;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.offline-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.offline-panel {
  display: grid;
  justify-items: center;
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow);
}

.offline-panel img {
  border-radius: 20px;
}

.offline-panel h1 {
  margin: 16px 0 6px;
  font-size: 22px;
}

.offline-panel p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.65;
}

@media (max-width: 720px) {
  .topbar-inner {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .brand-title {
    font-size: 20px;
  }

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

  .form-grid,
  .selection-bar,
  .selection-fields {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .section-head,
  .record-head,
  .card-head,
  .action-row {
    align-items: stretch;
  }

  .toolbar {
    display: grid;
  }

  .section-head,
  .selection-bar {
    align-items: stretch;
  }

  .action-row {
    flex-wrap: wrap;
  }

  .btn {
    min-width: 0;
  }

  .modal-backdrop {
    align-items: end;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .modal {
    max-height: 92vh;
  }
}
