:root {
  color-scheme: light;
  --paper: #F6F4F0;
  --ink: #1D1C1A;
  --muted: #77736D;
  --line: #D9D5CE;
  --fill: #E4E0D9;
  --wine: #76263C;
  --danger: #B3261E;
  --bar: rgba(246, 244, 240, .9);
  --gothic: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  font-family: var(--gothic);
  font-size: 15px;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  background: var(--paper);
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #151413;
    --ink: #F2EFEA;
    --muted: #9A958E;
    --line: #34312D;
    --fill: #2C2A27;
    --wine: #C8607A;
    --danger: #E5736B;
    --bar: rgba(21, 20, 19, .9);
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; min-height: 100dvh; margin: 0; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
::placeholder { color: var(--muted); opacity: .7; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

#app { width: min(100%, 760px); min-height: 100vh; margin: 0 auto; padding: env(safe-area-inset-top) 20px calc(104px + env(safe-area-inset-bottom)); outline: none; }
.page-header { position: sticky; top: 0; z-index: 20; min-height: 54px; display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; align-items: center; margin: 0 -20px 14px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--bar); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.page-header h1 { margin: 0; overflow: hidden; text-align: center; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 600; line-height: 1.25; }
.page-header.home-header { min-height: 62px; grid-template-columns: minmax(0, 1fr) 48px; }
.page-header.home-header > .header-spacer { display: none; }
.page-header.home-header h1 { text-align: left; font: 600 26px/1.2 var(--gothic); letter-spacing: .02em; }
.header-spacer { width: 48px; }
.header-action { min-width: 48px; min-height: 48px; display: grid; place-items: center; color: var(--ink); font-size: 13px; }
.icon-button { width: 48px; height: 48px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--ink); }
.icon-button svg { width: 24px; height: 24px; }

.install-guide { position: relative; z-index: 50; min-height: 56px; display: flex; align-items: center; gap: 8px; padding: calc(6px + env(safe-area-inset-top)) 12px 6px 16px; border-bottom: 1px solid var(--line); background: var(--ink); color: var(--paper); font-size: 13px; line-height: 1.4; }
.install-guide span { flex: 1; }
.install-guide .icon-button { flex: 0 0 48px; color: var(--paper); }
.sync-auth { position: relative; z-index: 60; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(6px + env(safe-area-inset-top)) 20px 6px; border-bottom: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 13px; line-height: 1.4; }
.sync-auth button { position: relative; flex: none; white-space: nowrap; min-height: 32px; padding: 0 14px; border: 0; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 13px; font-weight: 600; }
.sync-auth button::before { content: ""; position: absolute; inset: -8px -6px; }

.onboarding { min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 40px); max-width: 440px; display: flex; flex-direction: column; justify-content: center; gap: 12px; margin: auto; text-align: center; }
.app-icon { width: 104px; height: 104px; margin: 0 auto 16px; border: 1px solid var(--line); border-radius: 22%; }
.onboarding h1 { margin: 0; font: 600 26px/1.3 var(--gothic); letter-spacing: .02em; }
.onboarding p { margin: 0 0 16px; color: var(--muted); }
.owner-button { width: 100%; }
.onboarding .owner-button + .owner-button { border: 1px solid var(--ink); background: transparent; color: var(--ink); }

.home-controls { display: grid; gap: 8px; }
.search-box { height: 44px; display: flex; align-items: center; gap: 9px; padding: 0 13px; border: 1px solid var(--line); border-radius: 2px; }
.search-box svg { flex: 0 0 19px; width: 19px; height: 19px; color: var(--muted); }
.search-box input { width: 100%; height: 42px; padding: 0; border: 0; outline: 0; background: transparent; font-size: 16px; }
.segments { min-height: 48px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); }
.segments button { min-height: 46px; padding: 6px 12px; border: 0; border-left: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--ink); font-size: 15px; }
.segments button:first-child { border-left: 0; }
.segments button.selected { background: var(--ink); color: var(--paper); font-weight: 600; }
.type-group .segments button.selected { background: var(--wine); color: #FFFFFF; }
.segments.large { height: 48px; }
.filter-scroll { min-height: 44px; display: flex; gap: 8px; overflow-x: auto; margin: 0 -20px; padding: 5px 20px; border: 0; scrollbar-width: none; }
.filter-scroll::-webkit-scrollbar { display: none; }
.filter-scroll button, .chips button { position: relative; flex: 0 0 auto; min-height: 34px; padding: 5px 14px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--ink); font-size: 13px; white-space: nowrap; }
.filter-scroll button::before { position: absolute; inset: -5px 0; content: ""; }
.filter-scroll button.selected, .chips button.selected { border-color: var(--ink); background: var(--ink); color: var(--paper); font-weight: 600; }
.sort-row { min-height: 36px; display: flex; justify-content: flex-end; align-items: center; gap: 3px; color: var(--muted); font-size: 13px; }
.sort-row select { min-height: 36px; padding: 0 4px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; }

.entry-list { margin-top: 2px; padding-bottom: 26px; border-top: 1px solid var(--line); }
.entry-card { width: 100%; min-height: 88px; display: grid; grid-template-columns: 60px minmax(0, 1fr); gap: 12px; align-items: center; padding: 14px 0; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--ink); }
.entry-card > img, .entry-card > .empty-photo { width: 60px; height: 60px; border-radius: 6px; object-fit: cover; }
.entry-card-info { min-width: 0; display: grid; gap: 4px; align-content: center; }
.card-name { display: -webkit-box; overflow: hidden; font-size: 16px; font-weight: 600; line-height: 1.32; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.card-summary { min-width: 0; display: flex; align-items: baseline; gap: 7px; color: var(--muted); font-size: 13px; line-height: 1.3; white-space: nowrap; }
.card-summary > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.later-note { flex: 0 0 auto; color: var(--wine); font-size: 11px; }
.mini-ratings { display: flex; align-items: center; gap: 14px; min-width: 0; line-height: 1; }
.mini-rating { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.rating-name { color: var(--muted); font-size: 12px; }
.mini-rating svg { width: 11px; height: 11px; fill: var(--wine); stroke: var(--wine); }
.rating-number, .rating-empty { color: var(--ink); font-size: 13px; }
.empty-photo { display: grid; place-items: center; background: var(--fill); color: var(--muted); }
.empty-photo svg { width: 22px; height: 22px; }
.empty-state { padding: 48px 16px; text-align: center; }
.empty-state .brand-mark { width: 70px; height: 70px; display: flex; align-items: center; justify-content: center; gap: 2px; margin: 0 auto; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); }
.empty-state .brand-mark svg { width: 25px; height: 25px; }
.empty-state h2 { margin: 20px 0 8px; font: 600 19px/1.4 var(--gothic); }
.empty-state p { max-width: 420px; margin: 0 auto 22px; color: var(--muted); font-size: 13px; line-height: 1.6; }

.floating-add { position: fixed; z-index: 30; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); width: min(calc(100% - 40px), 720px); height: 56px; display: flex; align-items: center; justify-content: center; gap: 7px; transform: translateX(-50%); border-radius: 999px; background: var(--ink); color: var(--paper); box-shadow: 0 6px 18px rgba(20,18,16,.16); font-size: 16px; font-weight: 600; }
.floating-add svg { width: 20px; height: 20px; }
.primary-button, .secondary-button, .danger-button, .save-button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 18px; border: 1px solid transparent; border-radius: 999px; font-size: 15px; font-weight: 600; }
.primary-button, .save-button { background: var(--ink); color: var(--paper); }
.secondary-button { border-color: var(--ink); border-radius: 2px; background: transparent; color: var(--ink); }
.danger-button { background: transparent; color: var(--danger); font-weight: 400; }
.secondary-button.full { width: 100%; border: 0; border-radius: 0; background: transparent; color: var(--ink); }
.secondary-button.full + .secondary-button.full { border-top: 1px solid var(--line); }
button:disabled { opacity: .45; cursor: wait; }

.entry-form { margin: 0; }
.entry-form .page-header { margin-bottom: 8px; }
.form-content { display: grid; gap: 20px; }
.form-section { padding: 0; background: transparent; }
.form-section h2 { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 400; letter-spacing: .08em; }
.form-group-card, .detail-section, .settings-section { background: transparent; }
.form-group-card { padding: 0; }
.photo-group { padding: 0; }
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-actions .secondary-button { height: 48px; border-radius: 2px; }
.photo-actions.busy { opacity: .45; pointer-events: none; }
.photo-strip { display: flex; gap: 8px; overflow-x: auto; margin-top: 7px; }
.photo-strip:empty { display: none; }
.photo-item { position: relative; flex: 0 0 64px; height: 64px; }
.photo-item img { width: 64px; height: 64px; border-radius: 6px; object-fit: cover; }
.remove-photo { position: absolute; top: -5px; right: -5px; width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--ink); color: var(--paper); }
.remove-photo svg { width: 14px; height: 14px; }
.type-group { background: transparent; }
.field { min-height: 50px; display: grid; gap: 3px; align-content: center; margin: 0; border-bottom: 1px solid var(--line); font-weight: 400; }
.field > span, .field-title { color: var(--muted); font-size: 12px; letter-spacing: .08em; }
.name-field > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.name-field { border-bottom-color: var(--ink); }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; padding: 6px 0; border: 0; border-radius: 0; outline: 0; background: transparent; font-size: 16px; }
.field textarea { min-height: 106px; resize: vertical; line-height: 1.5; }
.rating-card { padding: 0; }
.rating-row { min-height: 48px; display: grid; grid-template-columns: 52px minmax(0, 1fr); align-items: center; border-bottom: 1px solid var(--line); }
.rating-row > span { font-size: 15px; }
.stars { display: grid; grid-template-columns: repeat(5, minmax(48px, 1fr)); justify-content: start; justify-items: center; }
.stars button { width: 48px; min-width: 48px; height: 48px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; color: var(--fill); }
.stars button svg { width: 26px; height: 26px; fill: currentColor; stroke: currentColor; }
.stars button.active { color: var(--wine); }
.details-panel { margin-top: 2px; border: 1px solid var(--line); border-radius: 2px; background: transparent; }
.details-panel summary { min-height: 50px; display: flex; align-items: center; padding: 0 14px; color: var(--ink); font-size: 15px; cursor: pointer; list-style: none; }
.details-panel summary::-webkit-details-marker { display: none; }
.details-panel summary::after { width: 8px; height: 8px; margin-left: auto; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); transform: rotate(-45deg); content: ""; }
.details-panel[open] summary::after { transform: rotate(45deg) translate(-2px, -2px); }
.details-body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.details-body h3 { margin: 22px 0 8px; font-size: 16px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.field + .chips { margin-top: 10px; }
.save-bar { position: fixed; z-index: 30; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); width: min(calc(100% - 40px), 720px); height: 56px; transform: translateX(-50%); }
.save-button { width: 100%; height: 56px; border-radius: 999px; box-shadow: 0 6px 18px rgba(20,18,16,.16); font-size: 16px; }
.form-open #app { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }

.detail-page { display: grid; gap: 16px; }
.detail-hero { width: 100%; max-height: 58vh; aspect-ratio: 4 / 5; border-radius: 6px; background: var(--fill); object-fit: contain; }
.detail-thumbs { display: flex; gap: 8px; overflow-x: auto; }
.detail-thumbs button { flex: 0 0 64px; width: 64px; height: 64px; padding: 2px; border: 1px solid transparent; border-radius: 6px; background: transparent; }
.detail-thumbs button.selected { border-color: var(--ink); }
.detail-thumbs img { width: 100%; height: 100%; border-radius: 4px; object-fit: cover; }
.detail-title { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.detail-title h2 { min-width: 100%; margin: 2px 0 0; font: 600 22px/1.35 var(--gothic); letter-spacing: .01em; }
.type-badge { color: var(--muted); font-size: 13px; }
.detail-date { margin: -9px 0 0; color: var(--muted); font-size: 13px; }
.detail-section { padding: 14px 0 0; border-top: 1px solid var(--line); }
.detail-section h3 { margin: 0 0 9px; font: 600 16px/1.4 var(--gothic); }
.detail-section .rating-row { margin-top: 0; }
.chips.readonly span { min-height: 34px; display: inline-flex; align-items: center; padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; }
.attribute-list { display: grid; grid-template-columns: minmax(98px, .75fr) 1.5fr; margin: 0; }
.attribute-list dt, .attribute-list dd { margin: 0; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.attribute-list dt { color: var(--muted); }
.attribute-list dd { text-align: right; overflow-wrap: anywhere; }
.memo { margin: 0; white-space: pre-wrap; line-height: 1.6; overflow-wrap: anywhere; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.detail-actions .primary-button { background: transparent; color: var(--ink); font-weight: 400; }

.settings-page { display: grid; gap: 0; }
.settings-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.settings-section h2 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.settings-section p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.settings-section .segments { margin-top: 12px; }
.settings-section .secondary-button.full { border: 1px solid var(--line); }
.settings-section .secondary-button.full + .secondary-button.full { border-top: 0; }
.share-login-form { display: grid; gap: 12px; }
.share-login-form .primary-button { width: 100%; }
/* 合言葉の欄は枠で囲んで、ひと目で入力欄だと分かるようにする */
.share-passphrase { margin-top: 4px; padding: 6px 14px 4px; border: 1px solid var(--ink); border-radius: 4px; }
.share-username { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.share-result { min-height: 1.4em; margin: 0; }
.import-result { min-height: 1.4em; margin-bottom: 0; color: var(--muted) !important; font-size: 13px; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 32px); min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; transform: translateX(-50%); border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 15px; }
.toast button { min-width: 48px; min-height: 44px; padding: 0 10px; border: 0; background: transparent; color: var(--paper); font-weight: 600; }
.fatal-error { padding: 40px 10px; text-align: center; }
.fatal-error p { color: var(--muted); }
.fatal-error pre { white-space: pre-wrap; }

button:active, a:active, summary:active { opacity: .55; }

@media (max-width: 390px) {
  .stars { margin-right: -5px; }
  .stars button { width: 48px; min-width: 48px; }
}

@media (max-width: 390px) and (max-height: 850px) {
  .entry-form .page-header { min-height: 48px; margin-bottom: 6px; }
  .entry-form .form-content { gap: 18px; }
  .entry-form .form-section h2 { margin-bottom: 7px; }
  .entry-form .photo-strip { margin-top: 5px; }
  .entry-form .photo-actions .secondary-button, .entry-form .segments, .entry-form .segments.large { height: 48px; min-height: 48px; }
  .entry-form .segments button { min-height: 44px; }
  .entry-form .field { min-height: 46px; }
}

@media (prefers-reduced-motion: no-preference) {
  button, a, summary { transition: opacity .12s ease, background-color .15s ease, color .15s ease; }
  .stars button:active svg { animation: star-pop .18s ease-out; }
  .details-panel summary::after { transition: transform .18s ease; }
  @keyframes star-pop { 50% { transform: scale(1.12); } }
}
