* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  background: #f6fff8;
  color: #1b4332;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

h1 {
  font-size: 2rem;
  margin: 0 0 4px;
}

.subtitle {
  margin: 0 0 20px;
  color: #52796f;
  font-size: 1.1rem;
}

.label {
  font-size: 1.1rem;
  margin: 0 0 10px;
}

.buyer-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.buyer-btn {
  padding: 16px;
  font-size: 1.2rem;
  border: 2px solid #95d5b2;
  border-radius: 12px;
  background: #fff;
  color: #1b4332;
}

.buyer-btn.selected {
  background: #2d6a4f;
  color: #fff;
  border-color: #2d6a4f;
}

.image-type-section {
  margin-bottom: 16px;
}

.image-type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.image-type-btn {
  padding: 14px;
  font-size: 1.05rem;
  border: 2px solid #95d5b2;
  border-radius: 12px;
  background: #fff;
  color: #1b4332;
}

.image-type-btn.selected {
  background: #40916c;
  color: #fff;
  border-color: #40916c;
}

.actions {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.big-btn {
  display: block;
  text-align: center;
  padding: 20px;
  font-size: 1.3rem;
  font-weight: 600;
  border-radius: 14px;
  cursor: pointer;
}

.camera-btn {
  background: #40916c;
  color: #fff;
}

.album-btn {
  background: #d8f3dc;
  color: #1b4332;
}

.preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.preview img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

.note-section input {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  border: 1px solid #b7e4c7;
  border-radius: 10px;
}

.hint {
  font-size: 0.9rem;
  color: #74a892;
  margin: 6px 0 0;
}

.submit-btn {
  width: 100%;
  padding: 18px;
  font-size: 1.4rem;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  background: #1b4332;
  color: #fff;
  margin-top: 8px;
}

.submit-btn:disabled {
  opacity: 0.4;
}

.status-msg {
  text-align: center;
  font-size: 1.1rem;
  margin-top: 14px;
  min-height: 1.4em;
}

.result {
  margin-top: 16px;
  padding: 14px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #b7e4c7;
}

.result h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.result ul {
  margin: 0;
  padding-left: 1.2em;
}

.hidden {
  display: none;
}

.pin-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f6fff8;
  padding: 16px;
  z-index: 100;
}

.pin-gate[hidden],
.pin-gate.hidden {
  display: none !important;
}

body.app-ready #pinGate {
  display: none !important;
}

body.app-ready #appMain {
  display: block !important;
}

#appMain[hidden] {
  display: none !important;
}

.pin-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: 0 8px 32px rgba(27, 67, 50, 0.12);
}

.pin-card h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.pin-hint {
  margin: 0 0 16px;
  color: #52796f;
  font-size: 0.95rem;
}

#pinInput {
  width: 100%;
  font-size: 1.25rem;
  padding: 14px 16px;
  border: 2px solid #b7e4c7;
  border-radius: 12px;
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: 0.15em;
}

.pin-error {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: #c1121f;
  font-size: 0.95rem;
  text-align: center;
}

.result-images {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.result-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

.result-meta {
  font-size: 0.9rem;
  color: #52796f;
  margin: 0 0 12px;
}

.result-edited-badge {
  display: inline-block;
  font-size: 0.8rem;
  background: #fff3cd;
  color: #856404;
  padding: 2px 8px;
  border-radius: 6px;
  margin-left: 6px;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.item-card {
  background: #f6fff8;
  border: 1px solid #d8f3dc;
  border-radius: 10px;
  padding: 12px;
  position: relative;
}

.item-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.item-name {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

.item-edit-btn {
  flex-shrink: 0;
  padding: 4px 12px;
  font-size: 0.9rem;
  border: 1px solid #95d5b2;
  border-radius: 8px;
  background: #fff;
  color: #2d6a4f;
}

.item-detail {
  font-size: 0.92rem;
  color: #52796f;
  margin: 3px 0;
  line-height: 1.45;
}

.item-storage {
  display: inline-block;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 6px;
  margin-right: 6px;
}

.storage-常温 { background: #fff3e0; color: #e65100; }
.storage-冷藏 { background: #e3f2fd; color: #1565c0; }
.storage-冷冻 { background: #e0f7fa; color: #00695c; }

.item-weight {
  font-size: 0.85rem;
  color: #74a892;
}

.result-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.result-btn {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid #95d5b2;
  background: #fff;
  color: #1b4332;
}

.result-btn.primary {
  background: #2d6a4f;
  color: #fff;
  border-color: #2d6a4f;
  font-weight: 600;
}

.item-editor {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(27, 67, 50, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.item-editor.hidden {
  display: none !important;
}

.item-editor-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 16px 16px 12px 12px;
  padding: 20px 16px;
  max-height: 85vh;
  overflow-y: auto;
}

.item-editor-card h3 {
  margin: 0 0 14px;
  font-size: 1.2rem;
}

.edit-field {
  display: block;
  margin-bottom: 12px;
  font-size: 0.95rem;
  color: #52796f;
}

.edit-field input,
.edit-field select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  font-size: 1.05rem;
  border: 1px solid #b7e4c7;
  border-radius: 10px;
}

.editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.editor-actions .danger {
  grid-column: 1 / -1;
}

.editor-btn {
  padding: 12px;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid #b7e4c7;
  background: #fff;
}

.editor-btn.primary {
  background: #2d6a4f;
  color: #fff;
  border-color: #2d6a4f;
}

.editor-btn.danger {
  color: #c1121f;
  border-color: #f5c2c7;
  background: #fff5f5;
}

.result-save-hint {
  text-align: center;
  font-size: 0.88rem;
  color: #c1121f;
  min-height: 1.2em;
  margin-top: 6px;
}

.recognition-fail {
  color: #c1121f;
  font-size: 1rem;
  line-height: 1.5;
  margin: 0;
}

.result-link {
  display: block;
  text-align: center;
  margin-top: 14px;
  font-size: 0.95rem;
  color: #2d6a4f;
  font-weight: 600;
  text-decoration: none;
}

.recent-section {
  margin-top: 24px;
}

.recent-list {
  display: grid;
  gap: 8px;
}

.recent-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border: 1px solid #d8f3dc;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.recent-buyer {
  font-weight: 600;
  color: #1b4332;
}

.recent-status {
  color: #74a892;
}
