:root {
  color-scheme: light dark;
  --bg: #f4f7f3;
  --surface: #ffffff;
  --surface-2: #eef4ef;
  --text: #17231b;
  --muted: #66736a;
  --border: #d9e2da;
  --primary: #2f6f4e;
  --primary-strong: #20573b;
  --primary-text: #ffffff;
  --accent: #dcefe3;
  --warning: #a95b00;
  --warning-soft: #fff0dc;
  --danger: #a73232;
  --danger-soft: #fbe5e5;
  --success: #247245;
  --shadow: 0 12px 36px rgba(23, 35, 27, 0.08);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
}

html[data-theme="dark"] {
  --bg: #101512;
  --surface: #18201b;
  --surface-2: #202a23;
  --text: #edf4ef;
  --muted: #a8b6ac;
  --border: #354139;
  --primary: #63a77f;
  --primary-strong: #82bd97;
  --primary-text: #0c1b12;
  --accent: #213b2b;
  --warning: #ffb75f;
  --warning-soft: #3b2c1d;
  --danger: #ff8d8d;
  --danger-soft: #402424;
  --success: #72c48f;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #101512;
    --surface: #18201b;
    --surface-2: #202a23;
    --text: #edf4ef;
    --muted: #a8b6ac;
    --border: #354139;
    --primary: #63a77f;
    --primary-strong: #82bd97;
    --primary-text: #0c1b12;
    --accent: #213b2b;
    --warning: #ffb75f;
    --warning-soft: #3b2c1d;
    --danger: #ff8d8d;
    --danger-soft: #402424;
    --success: #72c48f;
    --shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { width: min(760px, 100%); min-height: 100vh; margin: 0 auto; background: var(--bg); }
.app-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 14px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-bottom: 1px solid color-mix(in srgb, var(--border) 72%, transparent); }
.app-header h1 { margin: 2px 0 0; font-size: clamp(20px, 5vw, 27px); letter-spacing: -0.03em; }
.eyebrow { margin: 0; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.main-content { padding: 20px 16px calc(108px + var(--safe-bottom)); }
.view { display: none; }
.view.active { display: block; animation: fade-in 180ms ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 4px 2px 18px; }
.section-heading.compact { margin-top: 28px; margin-bottom: 12px; }
.section-heading h2, .section-heading h3 { margin: 3px 0 0; letter-spacing: -0.025em; }
.section-heading h2 { font-size: 26px; }
.section-heading h3 { font-size: 18px; }
.section-heading p:not(.eyebrow) { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.icon-button { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); font-size: 25px; line-height: 1; box-shadow: var(--shadow); cursor: pointer; }
.primary-button, .secondary-button, .danger-button, .text-button { border-radius: 14px; min-height: 46px; padding: 11px 16px; font-weight: 750; cursor: pointer; }
.primary-button { border: 1px solid var(--primary); background: var(--primary); color: var(--primary-text); }
.primary-button:hover { background: var(--primary-strong); }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.danger-button { border: 1px solid var(--danger); background: var(--danger-soft); color: var(--danger); }
.text-button { min-height: auto; padding: 7px 4px; border: 0; background: transparent; color: var(--primary); }
.primary-button.small { min-height: 40px; padding: 8px 13px; font-size: 14px; }
.full-width { width: 100%; }
.danger-text { color: var(--danger); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex="0"]:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }

.global-alert { margin-bottom: 18px; padding: 14px 16px; border: 1px solid color-mix(in srgb, var(--danger) 55%, var(--border)); border-radius: 16px; background: var(--danger-soft); color: var(--danger); font-weight: 750; cursor: pointer; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.summary-card { min-height: 108px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.summary-card strong { display: block; margin-top: 12px; font-size: 23px; letter-spacing: -0.03em; }
.summary-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.danger-soft { background: var(--danger-soft); }
.accent-soft { background: var(--accent); }
.status-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.status-pill { padding: 8px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 700; }
.status-pill.error { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.status-pill.ok { color: var(--success); }

.plant-list, .history-list, .settings-stack { display: grid; gap: 14px; }
.plant-card { overflow: hidden; border: 1px solid var(--border); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); scroll-margin-top: 100px; }
.plant-card.status-overdue { border-color: color-mix(in srgb, var(--danger) 60%, var(--border)); background: linear-gradient(135deg, var(--danger-soft), var(--surface) 56%); }
.plant-card.status-today, .plant-card.status-soon { border-color: color-mix(in srgb, var(--warning) 52%, var(--border)); background: linear-gradient(135deg, var(--warning-soft), var(--surface) 58%); }
.plant-card.highlight { animation: highlight 1.5s ease; }
@keyframes highlight { 0%, 100% { box-shadow: var(--shadow); } 40% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 35%, transparent), var(--shadow); } }
.plant-card-main { display: grid; grid-template-columns: 92px 1fr; gap: 14px; padding: 16px; }
.plant-photo { width: 92px; height: 110px; border-radius: 17px; object-fit: cover; background: var(--surface-2); }
.plant-placeholder { display: grid; place-items: center; width: 92px; height: 110px; border-radius: 17px; background: var(--accent); font-size: 42px; }
.plant-content { min-width: 0; }
.plant-title-row { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.plant-title-row h3 { margin: 0; overflow-wrap: anywhere; font-size: 21px; letter-spacing: -0.025em; }
.status-badge { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; padding: 6px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 800; }
.status-badge.overdue { background: var(--danger-soft); color: var(--danger); }
.status-badge.today, .status-badge.soon { background: var(--warning-soft); color: var(--warning); }
.status-badge.ok { background: var(--accent); color: var(--primary); }
.plant-dates { display: grid; gap: 6px; margin: 12px 0 0; }
.plant-dates p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.plant-dates strong { color: var(--text); }
.plant-memo { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.plant-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 9px; padding: 0 16px 16px; }
.water-button { min-height: 50px; }
.card-action { min-width: 50px; min-height: 50px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); color: var(--text); font-weight: 700; cursor: pointer; }
.empty-state { padding: 36px 22px; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); text-align: center; }
.empty-state .empty-icon { font-size: 44px; }
.empty-state h3 { margin: 10px 0 6px; }
.empty-state p { margin: 0 0 16px; color: var(--muted); line-height: 1.6; }

.history-card { padding: 16px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.history-header { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.history-header h3 { margin: 0; font-size: 17px; }
.history-card p { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.history-delete { border: 0; background: transparent; color: var(--danger); cursor: pointer; font-weight: 700; }

.settings-card { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.settings-card h3 { margin: 0 0 8px; }
.settings-note, .version-text { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.switch-row, .field-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 52px; border-top: 1px solid var(--border); }
.switch-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); }
.field-row input, .field-row select { min-width: 136px; }
.button-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.info-box { margin-top: 14px; padding: 12px 13px; border-radius: 14px; background: var(--surface-2); color: var(--muted); font-size: 12px; line-height: 1.6; }
.version-text { margin: 14px 0 0; text-align: center; }

.bottom-nav { position: fixed; left: 50%; bottom: 0; z-index: 25; transform: translateX(-50%); width: min(760px, 100%); display: grid; grid-template-columns: repeat(4, 1fr); padding: 8px 8px calc(8px + var(--safe-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-top: 1px solid var(--border); }
.nav-button { min-height: 54px; display: grid; place-items: center; align-content: center; gap: 2px; border: 0; border-radius: 14px; background: transparent; color: var(--muted); cursor: pointer; }
.nav-button span { font-size: 22px; line-height: 1; }
.nav-button small { font-size: 11px; font-weight: 800; }
.nav-button.active { background: var(--accent); color: var(--primary); }

.app-dialog { width: min(620px, calc(100% - 24px)); max-height: min(88vh, 820px); padding: 0; overflow: auto; border: 1px solid var(--border); border-radius: 24px; background: var(--surface); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.app-dialog::backdrop { background: rgba(6, 15, 9, .52); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.app-dialog > form, .app-dialog > div:not(.dialog-header):not(.dialog-actions) { padding-left: 20px; padding-right: 20px; }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: start; justify-content: space-between; gap: 14px; padding: 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 4px 0 0; font-size: 23px; }
.form-stack { display: grid; gap: 17px; padding: 20px 0; }
.form-stack label, .app-dialog > label { display: grid; gap: 7px; }
.form-stack label > span, .app-dialog > label > span { font-weight: 750; }
.form-stack b { margin-left: 5px; color: var(--danger); font-size: 11px; }
input, textarea, select { width: 100%; min-height: 46px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 13px; background: var(--bg); color: var(--text); }
textarea { resize: vertical; }
label small { color: var(--muted); line-height: 1.5; }
.field-error { min-height: 0; color: var(--danger); font-weight: 650; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.image-preview-wrap { display: flex; align-items: center; gap: 14px; }
.image-preview-wrap img { width: 92px; height: 92px; object-fit: cover; border-radius: 15px; }
.dialog-actions { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--border); }
.small-dialog { width: min(480px, calc(100% - 24px)); }
.snooze-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 20px; padding-bottom: 18px; }
.snooze-options button { min-height: 48px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); color: var(--text); font-weight: 750; cursor: pointer; }
.onboarding-dialog { padding-bottom: 20px; }
.onboarding-dialog > .primary-button { margin: 0 20px; width: calc(100% - 40px); }
.onboarding-steps { display: grid; gap: 14px; padding: 20px 28px 16px 48px; }
.onboarding-steps li { padding-left: 4px; }
.onboarding-steps strong, .onboarding-steps span { display: block; }
.onboarding-steps span { margin-top: 3px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom)); z-index: 60; transform: translateX(-50%); width: min(520px, calc(100% - 28px)); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 15px; border-radius: 15px; background: #17231b; color: #fff; box-shadow: 0 16px 50px rgba(0,0,0,.28); font-size: 14px; font-weight: 700; }
.toast-action { border: 0; background: transparent; color: #aee1be; font-weight: 800; cursor: pointer; }

@media (max-width: 520px) {
  .app-header { padding-left: 16px; padding-right: 16px; }
  .main-content { padding-left: 12px; padding-right: 12px; }
  .plant-card-main { grid-template-columns: 76px 1fr; padding: 14px; }
  .plant-photo, .plant-placeholder { width: 76px; height: 96px; border-radius: 15px; }
  .plant-placeholder { font-size: 35px; }
  .plant-actions { padding: 0 14px 14px; grid-template-columns: 1fr 48px 48px; }
  .card-action { min-width: 48px; padding: 6px; font-size: 12px; }
  .button-grid { grid-template-columns: 1fr; }
  .two-columns { grid-template-columns: 1fr; }
  .dialog-actions.stacked-mobile { flex-direction: column-reverse; }
  .dialog-actions.stacked-mobile button { width: 100%; }
}

@media (min-width: 680px) {
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .summary-card { min-height: 122px; }
}

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

#deletePlantButton { margin-right: auto; }

/* 家族共有 */
.share-panel { display: grid; gap: 14px; }
.stacked-field { display: grid; gap: 7px; }
.stacked-field > span { font-weight: 750; }
.share-action-box { display: grid; gap: 12px; padding: 15px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-2); }
.share-action-box h4 { margin: 0; font-size: 15px; }
.share-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 750; }
.share-divider::before, .share-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.share-code-panel { display: grid; gap: 10px; padding: 16px; border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--border)); border-radius: 17px; background: var(--accent); text-align: center; }
.share-code-panel strong { font-size: 27px; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.share-details { display: grid; gap: 8px; margin: 0; }
.share-details > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.share-details dt { color: var(--muted); font-size: 13px; font-weight: 700; }
.share-details dd { margin: 0; font-weight: 750; text-align: right; }
.sync-note { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.actor-note { margin: 7px 0 0; color: var(--primary); font-size: 12px; font-weight: 750; }
.status-pill.syncing { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); background: var(--accent); }
button:disabled { opacity: .58; cursor: not-allowed; }

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
}
.share-server-box { margin-bottom: 14px; }
.share-server-box input { font-size: 16px; }
.success-box { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); }
.share-details dd { overflow-wrap: anywhere; }

/* 家族コードだけで参加する簡単共有版 */
.share-join-box {
  border-color: color-mix(in srgb, var(--primary) 38%, var(--border));
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 72%, var(--surface)), var(--surface-2));
}
.share-step-badge {
  justify-self: start;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
}
.family-code-input {
  min-height: 58px;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.large-button { min-height: 54px; font-size: 16px; }
.admin-settings {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
}
.admin-settings summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}
.admin-settings[open] summary { border-bottom: 1px solid var(--border); }
.admin-settings-body { display: grid; gap: 13px; padding: 14px; }
.full-width-grid { grid-column: 1 / -1; }
.share-code-panel .sync-note { margin: 0; }
