:root {
    --bg: #f7efe3;
    --paper: #fffaf1;
    --paper-2: #f2e4d1;
    --ink: #2b1b12;
    --muted: #7b6758;
    --soft: #a99584;
    --line: rgba(73, 49, 33, 0.14);
    --brand: #b8502b;
    --brand-2: #d88b45;
    --green: #647c49;
    --blue: #476d84;
    --gold: #c79a3f;
    --danger: #a33a31;
    --white: #fff;
    --shadow: 0 18px 45px rgba(58, 35, 18, 0.14);
    --shadow-soft: 0 10px 24px rgba(58, 35, 18, 0.09);
    --radius: 8px;
    --radius-lg: 14px;
    --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100dvh;
    color: var(--ink);
    font-family: var(--font);
    background:
        linear-gradient(90deg, rgba(255,255,255,0.28) 1px, transparent 1px) 0 0 / 26px 26px,
        linear-gradient(180deg, #fbf5eb 0%, var(--bg) 42%, #f4e8d8 100%);
}

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
:focus-visible { outline: 3px solid rgba(184, 80, 43, 0.32); outline-offset: 3px; }

.app-shell {
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 18px 18px 96px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0 18px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(24px, 6vw, 42px); letter-spacing: 0; line-height: 1.05; }
h2 { font-size: clamp(28px, 9vw, 58px); line-height: 0.98; letter-spacing: 0; }
h3 { font-size: 20px; line-height: 1.2; }

.eyebrow {
    margin-bottom: 6px;
    color: var(--brand);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hero-panel {
    position: relative;
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 18px;
    align-items: end;
    margin-bottom: 22px;
    padding: 26px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background:
        linear-gradient(135deg, rgba(255,255,255,0.72), rgba(255,250,241,0.88)),
        radial-gradient(circle at 85% 10%, rgba(184,80,43,0.18), transparent 28%);
    box-shadow: var(--shadow-soft);
}

.date-line {
    margin-bottom: 12px;
    color: var(--muted);
    font-weight: 700;
}

.hero-copy p:last-child {
    max-width: 520px;
    margin-top: 14px;
    color: var(--muted);
    line-height: 1.7;
}

.today-strip {
    display: grid;
    gap: 8px;
    z-index: 1;
}

.today-item {
    display: grid;
    grid-template-columns: 54px 1fr;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 250, 241, 0.76);
    backdrop-filter: blur(8px);
}

.today-meal {
    color: var(--brand);
    font-size: 12px;
    font-weight: 800;
}

.today-food {
    min-width: 0;
    font-weight: 750;
}

.today-food > span:first-child {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.today-thumbs {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    overflow-x: auto;
    scrollbar-width: none;
}
.today-thumbs::-webkit-scrollbar { display: none; }

.today-thumb {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    cursor: pointer;
}

.quick-record {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.quick-record .primary-btn {
    min-height: 52px;
    padding: 0 32px;
    font-size: 16px;
}

.share-controls, .month-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.primary-btn, .ghost-btn, .icon-action {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    min-height: 44px;
    padding: 0 16px;
    font-weight: 800;
    cursor: pointer;
}

.primary-btn {
    color: #fffaf3;
    border-color: transparent;
    background: linear-gradient(135deg, var(--brand), #cf7138);
    box-shadow: 0 8px 18px rgba(184, 80, 43, 0.2);
}

.ghost-btn, .icon-action {
    color: var(--ink);
    background: rgba(255, 250, 241, 0.78);
}

.primary-btn:disabled, .ghost-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

.full { width: 100%; }
.icon-action {
    display: inline-grid;
    place-items: center;
    min-width: 44px;
    padding: 0 12px;
    font-size: 24px;
    line-height: 1;
}

.tabs-section { margin: 8px 0 20px; }
.segmented {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 10px;
    scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.tab-btn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 15px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255,250,241,0.72);
    font-weight: 800;
}
.tab-btn.active {
    color: #fffaf3;
    border-color: transparent;
    background: var(--ink);
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    margin-bottom: 18px;
}

.panel {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: rgba(255, 250, 241, 0.82);
    box-shadow: var(--shadow-soft);
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 14px;
    margin-bottom: 16px;
}

.hint, .small-note {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.food-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.food-chip {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 42px;
    gap: 0;
    min-height: 76px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--food-bg, linear-gradient(135deg, #f0d2a8, #c86c42));
    color: #fffaf3;
}

.food-chip::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(38, 22, 13, 0.72), rgba(38, 22, 13, 0.14));
    pointer-events: none;
}

.food-pick {
    position: relative;
    z-index: 1;
    min-width: 0;
    border: 0;
    color: inherit;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.food-pick span {
    position: relative;
    z-index: 1;
    display: block;
    padding: 12px;
    font-weight: 900;
}

.food-pick small {
    position: relative;
    z-index: 1;
    display: block;
    padding: 0 12px 12px;
    opacity: 0.86;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.food-delete {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    border: 0;
    border-left: 1px solid rgba(255, 250, 243, 0.24);
    color: #fffaf3;
    background: rgba(35, 20, 12, 0.16);
    cursor: pointer;
    font-size: 20px;
    font-weight: 900;
}

.custom-food-row {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr 0.8fr 1fr 44px;
    gap: 8px;
    margin-top: 12px;
}

.text-input, .select-input, textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 12px;
    color: var(--ink);
    background: rgba(255,255,255,0.66);
}

.select-label, .field span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.share-controls { display: grid; grid-template-columns: 1fr 1fr; }
.share-controls .select-label, .share-controls .select-input { grid-column: 1 / -1; }
.share-output { margin-top: 12px; }
textarea {
    min-height: 84px;
    resize: vertical;
    padding: 10px;
    line-height: 1.5;
}
.share-output .primary-btn { margin-top: 8px; width: 100%; }

.month-panel { margin-bottom: 24px; }
.calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
}

.price-panel { margin-bottom: 18px; }

.price-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.price-grid th {
    padding: 6px 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

.price-grid td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
}

.price-grid tr:last-child td { border-bottom: none; }

.price-label {
    color: var(--muted);
    font-weight: 800;
}

.price-value {
    font-size: 18px;
    font-weight: 900;
    color: var(--brand);
}

.price-count {
    color: var(--muted);
}

.site-footer {
    margin: 26px 0 8px;
    padding: 18px 2px 0;
    border-top: 1px solid var(--line);
}

.site-footer p {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.8;
}

.weekday {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-align: center;
}

.day-card {
    min-height: 80px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.48);
}

.day-card.empty {
    opacity: 0.18;
    background: rgba(255,255,255,0.28);
    border-style: dashed;
}
.day-card.today {
    border-color: rgba(184,80,43,0.5);
    box-shadow: inset 0 0 0 1px rgba(184,80,43,0.18);
}
.day-card.has-logs { cursor: pointer; }
.day-card.has-logs:hover { background: rgba(255,255,255,0.72); }

.day-num {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    margin-bottom: 4px;
}

.day-photo-icon { font-size: 10px; }

.day-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.meal-tag {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--tag-color, var(--brand));
    color: #fffaf3;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
}

.detail-row {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: none; }

.detail-main {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.detail-meal {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.detail-food {
    font-weight: 750;
    flex: 1;
}

.detail-price {
    color: var(--brand);
    font-weight: 800;
    font-size: 13px;
}

.detail-note {
    margin-top: 4px;
    padding-left: 13px;
    color: var(--muted);
    font-size: 12px;
}

.detail-thumb {
    display: block;
    width: 100%;
    max-height: 120px;
    object-fit: cover;
    border-radius: 6px;
    margin-top: 6px;
    cursor: pointer;
}

.meal-dot {
    flex: 0 0 7px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--brand);
}

.meal-delete {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--soft);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
    border-radius: 50%;
}

.meal-delete:hover {
    background: rgba(163, 58, 49, 0.12);
    color: var(--danger);
}

.thumb {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    object-fit: cover;
}

.bottom-bar {
    position: fixed;
    left: 50%;
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 20;
    display: none;
    width: min(calc(100% - 24px), 480px);
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 250, 241, 0.88);
    box-shadow: 0 14px 34px rgba(43, 27, 18, 0.18);
    backdrop-filter: blur(14px);
    transform: translateX(-50%);
}

.bottom-bar button {
    flex: 1;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    color: var(--ink);
    background: transparent;
    font-weight: 900;
}
.bottom-bar button:nth-child(2) {
    color: #fffaf3;
    background: var(--brand);
}
.bottom-bar button:disabled { opacity: 0.38; }

.record-dialog {
    width: min(92vw, 520px);
    padding: 0;
    border: 0;
    background: transparent;
}
.record-dialog::backdrop { background: rgba(37, 23, 13, 0.42); backdrop-filter: blur(7px); }
.dialog-card {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--paper);
    box-shadow: var(--shadow);
}
.dialog-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.meal-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}
.meal-option {
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255,255,255,0.58);
    font-weight: 900;
}
.meal-option.active {
    color: #fffaf3;
    border-color: transparent;
    background: var(--ink);
}

.field { display: block; margin-bottom: 14px; }

.photo-picker {
    display: grid;
    place-items: center;
    min-height: 150px;
    margin-bottom: 16px;
    overflow: hidden;
    border: 1px dashed rgba(73,49,33,0.32);
    border-radius: var(--radius);
    color: var(--muted);
    background: rgba(255,255,255,0.46);
    font-weight: 800;
}
.photo-picker input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }
.photo-picker img { width: 100%; max-height: 260px; object-fit: cover; }

.poster-preview-wrap {
    display: grid;
    place-items: center;
    min-height: 260px;
    max-height: 62vh;
    overflow: auto;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,0.48);
}
.poster-preview-wrap img { width: 100%; height: auto; display: block; }
.poster-loading { color: var(--muted); font-weight: 800; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(92px + env(safe-area-inset-bottom));
    z-index: 50;
    max-width: min(420px, calc(100% - 32px));
    padding: 12px 14px;
    border-radius: 12px;
    color: #fffaf3;
    background: rgba(43, 27, 18, 0.9);
    box-shadow: var(--shadow-soft);
    opacity: 0;
    transform: translate(-50%, 10px);
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.read-only .custom-food-row,
.read-only .quick-record,
.read-only #tabsSection,
.read-only .content-grid,
.read-only .price-panel,
.read-only #shareControls,
.read-only #bottomBar {
    display: none;
}
.read-only .hero-panel { grid-template-columns: 1fr; }

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    place-items: center;
    background: rgba(0, 0, 0, 0.88);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.lightbox:not([hidden]) {
    display: grid;
}

.lightbox img {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox-close {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
}

@supports (-webkit-touch-callout: none) {
    .text-input, .select-input, textarea, .record-dialog input, .record-dialog select {
        font-size: 16px;
    }
}

@media (max-width: 780px) {
    .app-shell { padding: 14px 12px calc(96px + env(safe-area-inset-bottom)); }
    .hero-panel, .content-grid { grid-template-columns: 1fr; }
    .hero-panel { padding: 20px; }
    .bottom-bar { display: flex; }
    .calendar { gap: 5px; }
    .day-card { min-height: 68px; padding: 5px; }
    .meal-grid { grid-template-columns: repeat(2, 1fr); }
    .custom-food-row { grid-template-columns: 1fr 1fr; }
    .custom-food-row #customFoodInput,
    .custom-food-row #customTagInput { grid-column: 1 / -1; }
    .record-dialog { width: min(96vw, 520px); }
    .dialog-card { padding: 16px; max-height: 90dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 430px) {
    .food-list { grid-template-columns: 1fr; }
    .share-controls { grid-template-columns: 1fr; }
    .calendar { grid-template-columns: repeat(7, 1fr); }
    .weekday { font-size: 10px; }
    .day-card { min-height: 60px; }
    .meal-tag { font-size: 9px; padding: 0 3px; }
    .meal-delete { opacity: 1; flex: 0 0 24px; width: 24px; height: 24px; font-size: 16px; }
    .today-food { white-space: normal; }
    .today-thumb { width: 28px; height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
