*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fff8f0;
  --surface: #ffffff;
  --text: #2d1810;
  --text-muted: #8b7355;
  --primary: #e85d04;
  --primary-dark: #c44900;
  --accent: #f48c06;
  --border: #f0e0d0;
  --shadow: 0 2px 12px rgba(45, 24, 16, 0.08);
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  padding-bottom: calc(20px + var(--safe-bottom));
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  padding: 28px 20px 24px;
  text-align: center;
}

.header__title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header__subtitle {
  font-size: 0.875rem;
  opacity: 0.9;
  margin-top: 4px;
}

.header__user {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 0.8125rem;
}

.header__email {
  opacity: 0.95;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header__logout {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.75rem;
  cursor: pointer;
}

.header__logout:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Main */
.main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

/* Toolbar */
.toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.97);
}

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--primary-dark);
}

.btn--accent {
  background: var(--surface);
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Filters */
.filters {
  margin-bottom: 16px;
}

.search-wrap {
  margin-bottom: 10px;
}

.search {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--surface);
  font-family: inherit;
}

.search:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cat-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-muted);
  transition: all 0.15s;
}

.cat-btn--active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Dish list */
.dish-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dish-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 10px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dish-card__thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.dish-card__thumb--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 1.25rem;
}

.dish-card__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  padding: 4px 0;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.dish-card__body:hover .dish-card__name {
  color: var(--primary);
}

.dish-card__name {
  font-size: 1rem;
  font-weight: 500;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dish-card__actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--bg);
}

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  background: #fff3e6;
  color: var(--primary);
  font-weight: 500;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 20px;
  font-size: 0.9375rem;
}

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: calc(100vw - 32px);
  width: 420px;
  box-shadow: 0 8px 32px rgba(45, 24, 16, 0.2);
}

.modal::backdrop {
  background: rgba(45, 24, 16, 0.4);
}

.modal__content {
  padding: 24px;
}

.modal__title {
  font-size: 1.25rem;
  margin-bottom: 20px;
}

.modal__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Random result */
.random-result {
  text-align: center;
}

.random-result__label {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 8px;
}

.random-result__name {
  font-size: 1.75rem;
  color: var(--primary);
  margin-bottom: 12px;
}

.random-result__photo {
  margin: 12px 0 4px;
  border-radius: var(--radius);
  overflow: hidden;
}

.random-result__photo img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

/* Photo area */
.photo-area {
  margin-bottom: 12px;
}

.btn--full {
  width: 100%;
  margin-bottom: 12px;
}

.photo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 160px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--text-muted);
  transition: border-color 0.15s;
}

.photo-placeholder:hover {
  border-color: var(--primary);
}

.photo-placeholder__icon {
  font-size: 2rem;
}

.photo-placeholder__hint {
  font-size: 0.75rem;
  opacity: 0.8;
}

.photo-preview {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
}

.photo-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
}

.photo-preview__actions {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.photo-preview__btn {
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: inherit;
}

.analyze-status {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 12px;
}

.analyze-status--loading {
  background: #fff3e6;
  color: var(--primary);
}

.analyze-status--error {
  background: #fde8e8;
  color: #c0392b;
}

.analyze-status--success {
  background: #e8f8ef;
  color: #27ae60;
}

/* Form fields */
.field {
  display: block;
  margin-bottom: 14px;
}

.field__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.field__input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
}

.field__input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.field__hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Detail view */
.detail-view {
  text-align: center;
}

.detail-view__photo {
  margin-bottom: 16px;
  border-radius: var(--radius);
  overflow: hidden;
}

.detail-view__photo img {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  display: block;
}

.detail-view__name {
  font-size: 1.5rem;
  margin-bottom: 10px;
}

.detail-view__meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 12px;
}

.detail-view__actions {
  justify-content: center;
  flex-wrap: wrap;
}

/* Auth */
.auth-modal::backdrop {
  background: rgba(45, 24, 16, 0.6);
}

.auth-form__hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.auth-tab {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 0.9375rem;
  cursor: pointer;
}

.auth-tab--active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.auth-status {
  font-size: 0.8125rem;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.auth-status--error {
  background: #fde8e8;
  color: #c0392b;
}

.auth-status--loading {
  background: #fff3e0;
  color: var(--primary-dark);
}

.btn--full {
  width: 100%;
}

@media (min-width: 560px) {
  .header__title {
    font-size: 2rem;
  }
}
