:root {
  color-scheme: light;
  --ink: #1d2422;
  --muted: #62706c;
  --canvas: #f5f2ea;
  --paper: #fffdf7;
  --line: #d8ded7;
  --green: #173f35;
  --green-soft: #e2ece5;
  --wine: #7b3540;
  --wine-soft: #f4e7e9;
  --gold: #b77a20;
  --shadow: 0 6px 20px rgb(26 48 42 / 8%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; background: var(--canvas); color: var(--ink); }

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

.shell { width: min(100%, 680px); min-height: 100dvh; margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(88px + env(safe-area-inset-bottom)); }
.app-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.app-title { margin: 0; color: var(--green); font-size: 21px; font-weight: 700; letter-spacing: 0; }
.date-label { color: var(--muted); font-size: 13px; }

.text-button, .submit-button, .secondary-button, .tab-button, .scene-button { border: 0; background: none; }
.text-button { color: var(--wine); padding: 8px 0; font-size: 14px; }
.submit-button { width: 100%; min-height: 48px; border: 0; border-radius: 7px; background: var(--green); color: #fff; font-weight: 700; }
.submit-button:disabled { cursor: not-allowed; background: #a6b2ad; }
.secondary-button { min-height: 42px; padding: 0 15px; border: 1px solid var(--green); border-radius: 6px; color: var(--green); background: transparent; font-weight: 650; }
.secondary-button:disabled { color: var(--muted); border-color: var(--line); }

.update-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; margin: 12px 0; border: 1px solid #d6b96e; background: #fff7db; color: #5e4c18; font-size: 13px; }
.update-banner button { border: 0; background: transparent; color: #5e4c18; font-weight: 700; padding: 4px; }

.login-shell { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(100%, 390px); }
.login-panel h1 { margin: 0 0 10px; color: var(--green); font-size: 30px; }
.login-panel p { margin: 0 0 28px; color: var(--muted); line-height: 1.6; }
.field-label { display: block; margin: 0 0 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
.text-input, .note-input, .select-input { width: 100%; border: 1px solid #c7d0ca; border-radius: 6px; background: var(--paper); color: var(--ink); outline: none; }
.text-input, .select-input { min-height: 48px; padding: 0 13px; }
.note-input { min-height: 92px; padding: 12px; resize: vertical; line-height: 1.5; }
.text-input:focus, .note-input:focus, .select-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgb(23 63 53 / 12%); }
.login-actions { display: grid; gap: 12px; margin-top: 18px; }
.hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.content { padding-top: 18px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 26px 0 10px; }
.section-heading h2 { margin: 0; font-size: 17px; color: var(--green); }
.section-heading span { color: var(--muted); font-size: 12px; }
.setup-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.temperature-heading { display: flex; align-items: center; justify-content: space-between; }
.temperature-heading .field-label { margin-bottom: 0; }
.temperature-value { color: var(--green); font-size: 20px; font-weight: 750; line-height: 1; }
.temperature-slider { width: 100%; height: 32px; margin: 8px 0 0; accent-color: var(--green); cursor: pointer; }
.temperature-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.temperature-status { margin-top: 8px; min-height: 20px; color: var(--muted); font-size: 13px; }
.offline-banner { padding: 10px 16px; color: #6c421a; background: #fff2da; border-bottom: 1px solid #eed0a2; font-size: 13px; }

.scene-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid #c7d0ca; border-radius: 7px; overflow: hidden; background: var(--paper); }
.scene-button { min-height: 42px; padding: 0 3px; color: var(--muted); font-size: 13px; border-right: 1px solid #c7d0ca; }
.scene-button:last-child { border-right: 0; }
.scene-button.is-active { color: #fff; background: var(--green); font-weight: 700; }

.selection-strip { margin-top: 18px; padding: 13px 0 15px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.selection-summary { display: flex; min-height: 78px; gap: 9px; overflow-x: auto; padding: 2px 0; }
.selection-thumb { width: 76px; height: 76px; flex: 0 0 76px; border: 1px solid var(--wine); border-radius: 5px; object-fit: cover; background: var(--paper); }
.selection-empty { align-self: center; color: var(--muted); font-size: 13px; }
.validation-text { min-height: 20px; margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.validation-text.is-ready { color: var(--green); }

.category { margin-top: 26px; }
.category-title { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; }
.category-title h3 { margin: 0; font-size: 15px; }
.category-title span { color: var(--muted); font-size: 12px; }
.item-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.item-card { position: relative; min-width: 0; padding: 0; overflow: hidden; border: 1px solid #cdd5cf; border-radius: 7px; background: var(--paper); text-align: left; box-shadow: none; }
.item-card.is-priority { border-color: #aac6b5; background: var(--green-soft); }
.item-card.is-selected { border: 2px solid var(--wine); }
.item-image { display: block; width: 100%; aspect-ratio: 5 / 4; object-fit: cover; background: #e8e8df; }
.item-copy { min-height: 74px; padding: 9px 10px 10px; }
.item-name { display: block; overflow: hidden; font-size: 13px; font-weight: 700; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.item-color { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.priority-mark { position: absolute; top: 8px; left: 8px; padding: 4px 6px; border-radius: 4px; background: var(--green); color: #fff; font-size: 11px; font-weight: 700; }
.selection-mark { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--wine); color: #fff; font-size: 14px; font-weight: 700; }
.empty-state { padding: 28px 0; color: var(--muted); text-align: center; font-size: 14px; }
.note-block { margin-top: 24px; }
.submit-area { margin-top: 24px; }
.save-note { margin: 9px 0 0; color: var(--muted); text-align: center; font-size: 12px; }

.history-list { display: grid; gap: 18px; }
.history-row { padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.history-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 7px 12px; margin-bottom: 9px; }
.history-date { color: var(--green); font-size: 15px; font-weight: 750; }
.history-detail { color: var(--muted); font-size: 13px; }
.history-images { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
.history-images img { width: 100%; aspect-ratio: 1 / 1; border-radius: 4px; object-fit: cover; background: var(--paper); }
.history-note { margin: 9px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.load-more { display: block; margin: 22px auto; }

.filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.filter-grid .full { grid-column: 1 / -1; }
.custom-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stats-total { margin: 22px 0 0; color: var(--muted); font-size: 13px; }
.rank-list { display: grid; gap: 10px; }
.rank-row { display: flex; align-items: center; gap: 10px; min-width: 0; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.rank-count { width: 28px; flex: 0 0 28px; color: var(--wine); font-size: 15px; font-weight: 750; text-align: right; }
.rank-images { display: flex; min-width: 0; flex: 1; gap: 4px; overflow: hidden; }
.rank-images img { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 4px; object-fit: cover; }
.rank-name { min-width: 0; flex: 1; overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.bar-list { display: grid; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 74px minmax(0, 1fr) 28px; align-items: center; gap: 8px; font-size: 12px; }
.bar-label { color: var(--muted); }
.bar-track { height: 8px; overflow: hidden; background: #dfe5df; }
.bar-fill { height: 100%; background: var(--gold); }
.bar-value { color: var(--wine); font-weight: 750; text-align: right; }

.bottom-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 4; display: flex; justify-content: center; padding: 8px max(16px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: rgb(255 253 247 / 96%); backdrop-filter: blur(12px); }
.bottom-nav-inner { width: min(100%, 680px); display: grid; grid-template-columns: repeat(3, 1fr); }
.tab-button { min-height: 42px; color: var(--muted); font-size: 13px; }
.tab-button.is-active { color: var(--green); font-weight: 750; }
.message { margin: 16px 0; padding: 11px 12px; border-left: 3px solid var(--wine); background: var(--wine-soft); color: #5f202b; font-size: 13px; line-height: 1.45; }
.message.is-success { border-color: var(--green); background: var(--green-soft); color: var(--green); }

@media (min-width: 560px) {
  .setup-grid { grid-template-columns: 180px minmax(0, 1fr); align-items: end; }
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-grid .full { grid-column: auto; }
}
