:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --text: #1c1c1e;
  --text-sub: #8a8a8e;
  --border: #e5e5ea;
  --primary: #ff7043;
  --primary-press: #f4602e;
  --danger: #ff3b30;
  --radius: 14px;
  --tabbar-h: 56px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #ffffff;
    --text-sub: #98989f;
    --border: #2c2c2e;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button {
  font-family: inherit;
  cursor: pointer;
}
input,
textarea {
  font-family: inherit;
  font-size: 16px;
}

/* header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}
.header-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 8px;
}
.header-btn:active {
  background: var(--border);
}
.field-hint {
  font-size: 12px;
  color: var(--text-sub);
  margin: 8px 2px 0;
}

/* main */
#main {
  padding: 12px 12px calc(var(--tabbar-h) + var(--safe-bottom) + 80px);
}
.view {
  display: none;
}
.view.active {
  display: block;
}

/* cards */
.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: transform 0.08s ease;
}
.card:active {
  transform: scale(0.985);
}
.card-main {
  flex: 1;
  min-width: 0;
}
.card-title {
  font-weight: 600;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-sub {
  color: var(--text-sub);
  font-size: 13px;
  margin-top: 2px;
}
.card-chevron {
  color: var(--text-sub);
  font-size: 22px;
  line-height: 1;
}

.empty {
  text-align: center;
  color: var(--text-sub);
  padding: 48px 16px;
  font-size: 14px;
}
.hidden {
  display: none !important;
}

/* inline add (inventory) */
.inline-add {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.inline-add input {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
#inv-name {
  flex: 1;
}
#inv-amount {
  flex: 0 0 84px;
}
.btn-add {
  flex: 0 0 auto;
  padding: 0 16px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.btn-add:active {
  background: var(--primary-press);
}

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  line-height: 56px;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  z-index: 20;
}
.fab:active {
  background: var(--primary-press);
}

/* tabbar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 11px;
}
.tab.active {
  color: var(--primary);
}
.tab-icon {
  font-size: 22px;
  line-height: 1;
}

/* modal sheet */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
}
.modal.hidden {
  display: none;
}
.modal-sheet {
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 24px);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 10px 0;
  margin-bottom: 4px;
}
.sheet-actions {
  display: flex;
  gap: 2px;
}
.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 16px;
  padding: 6px 8px;
  border-radius: 8px;
}
.btn-text.primary {
  font-weight: 700;
}
.btn-text.danger {
  color: var(--danger);
}

/* detail */
.detail-title {
  font-size: 22px;
  margin: 4px 0 12px;
}
.source-link {
  display: inline-block;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 0;
}
.detail-section {
  margin-top: 18px;
}
.detail-section h3 {
  font-size: 14px;
  color: var(--text-sub);
  margin: 0 0 8px;
  font-weight: 600;
}
.ingredient-view {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ingredient-view li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.ing-name {
  font-weight: 500;
}
.ing-amount {
  color: var(--text-sub);
}
.body-text {
  white-space: pre-wrap;
  margin: 0;
}

/* form */
.form-label {
  display: block;
  font-size: 13px;
  color: var(--text-sub);
  margin: 16px 0 6px;
  font-weight: 600;
}
.field {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
textarea.field {
  resize: vertical;
  line-height: 1.6;
}
.ing-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ing-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.ing-input-name {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.ing-input-amount {
  flex: 0 0 84px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.btn-remove {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  color: var(--text-sub);
  font-size: 18px;
  line-height: 1;
}
.btn-secondary {
  margin-top: 10px;
  width: 100%;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: none;
  color: var(--primary);
  font-weight: 600;
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 80px);
  transform: translateX(-50%) translateY(10px);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
  pointer-events: none;
  max-width: 86%;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
