:root {
  --green: #2E7D32;
  --green-dark: #1B5E20;
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1c1e1c;
  --muted: #6b7280;
  --border: #d9dcd7;
  --danger: #c62828;
  --amber: #f5b100;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--green);
  color: #fff;
  padding: max(env(safe-area-inset-top), 8px) 12px 8px;
  min-height: 44px;
}
.appbar-title { font-size: 1.15rem; margin: 0; font-weight: 600; }
.appbar-back {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
}

#main { padding: 14px; padding-bottom: calc(env(safe-area-inset-bottom) + 24px); max-width: 640px; margin: 0 auto; }
.screen { display: block; }

/* ---- buttons ---- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-lg { padding: 16px; font-size: 1.1rem; width: 100%; }
.btn-sm { padding: 7px 10px; font-size: .85rem; }
.btn-link { background: none; border: none; box-shadow: none; color: var(--green); text-decoration: underline; padding: 6px 0; }

.review-links { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.ocr-text > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  list-style: none;
}
.ocr-text > summary::-webkit-details-marker { display: none; }
.ocr-text > summary::before { content: "▸ "; }
.ocr-text[open] > summary::before { content: "▾ "; }
.ocr-text pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0 0;
  font-size: .8rem;
  max-height: 240px;
  overflow: auto;
  -webkit-user-select: text;
  user-select: text;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}
.toolbar-wrap { flex-wrap: wrap; }
.toolbar .btn { flex: 1 1 auto; }

/* ---- home ---- */
.home-hero { text-align: center; padding: 32px 12px 20px; }
.home-logo { font-size: 4rem; }
.home-tag { color: var(--muted); max-width: 340px; margin: 12px auto 0; line-height: 1.4; }
.home-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* ---- camera ---- */
.camera-wrap {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
}
#video { width: 100%; height: 100%; object-fit: cover; }
.camera-msg { color: #fff; padding: 20px; text-align: center; }
.btn-shutter {
  border-radius: 50%;
  width: 68px;
  height: 68px;
  font-size: 1.6rem;
  flex: 0 0 auto;
}

/* ---- native camera (iOS) ---- */
.native-cam {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 24px 8px;
  text-align: center;
}
.native-cam-art { font-size: 3.4rem; }
.native-cam .hint { margin: 0 0 6px; }

/* ---- crop ---- */
.hint, .processing-status { color: var(--muted); font-size: .9rem; }
.hint { margin: 4px 0 10px; text-align: center; }
.crop-rotate-row { display: flex; gap: 10px; justify-content: center; margin-bottom: 8px; }
.crop-wrap {
  display: flex;
  justify-content: center;
  background: #222;
  border-radius: 12px;
  padding: 8px;
  overflow: auto;
}
#crop-canvas { touch-action: none; display: block; border-radius: 4px; }

/* ---- processing ---- */
.processing-box { text-align: center; padding: 48px 16px; }
.spinner {
  width: 46px; height: 46px;
  border: 5px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  margin: 0 auto 18px;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  max-width: 280px;
  margin: 14px auto 0;
}
.progress-bar { height: 100%; width: 0%; background: var(--green); transition: width .2s; }
.processing-error { color: var(--danger); margin-top: 16px; }

/* ---- forms ---- */
.field { display: block; margin: 12px 0; }
.field-label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=number], textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
}
textarea { resize: vertical; }

/* ---- review items ---- */
.items-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.items-head h2 { font-size: 1.05rem; margin: 0; }
.items-head-actions { display: flex; gap: 8px; }
.items-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.item-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: var(--shadow);
}
.item-row1 { display: flex; align-items: center; gap: 8px; }
.item-row1 input[type=checkbox] { width: 20px; height: 20px; flex: 0 0 auto; }
.item-name { flex: 1 1 auto; }
.item-price { width: 90px; flex: 0 0 auto; text-align: right; }
.item-row2 { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 8px; }
.stars { display: inline-flex; gap: 2px; }
.star {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--border);
  padding: 2px;
}
.star.on { color: var(--amber); }
.item-comment { margin-top: 8px; }
.item-comment[hidden] { display: none; }

/* ---- history ---- */
.history-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.history-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.history-card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.history-meta { color: var(--muted); font-size: .85rem; display: flex; gap: 10px; flex-wrap: wrap; }
.empty-msg { color: var(--muted); text-align: center; margin-top: 40px; }

/* ---- detail ---- */
.detail-photo { width: 100%; border-radius: 12px; border: 1px solid var(--border); margin-bottom: 12px; }
.detail-section { margin: 14px 0; }
.detail-section h3 { margin: 0 0 6px; font-size: .95rem; color: var(--muted); }
.detail-dish {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
}
.detail-dish-top { display: flex; justify-content: space-between; gap: 8px; }
.detail-dish-name { font-weight: 600; }
.detail-dish-comment { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.static-stars { color: var(--amber); letter-spacing: 2px; }

/* ---- modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-inner { max-width: 100%; max-height: 100%; display: flex; flex-direction: column; gap: 12px; align-items: center; }
#photo-modal-img { max-width: 100%; max-height: 78vh; border-radius: 8px; }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 60;
  box-shadow: var(--shadow);
}

[hidden] { display: none !important; }
