:root {
    --primary: #006b5e;
    --primary-light: #e6f4f1;
    --bg: #f5f7f8;
    --card: #ffffff;
    --text: #222;
    --sub: #666;
    --border: #e0e4e7;
    --danger: #c9302c;
    --husband-bg: #e3f2fd; --husband: #1565c0;
    --wife-bg: #fce8ef; --wife: #c2185b;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
    background: var(--bg); color: var(--text);
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
    -webkit-tap-highlight-color: transparent;
  }
  [hidden] { display: none !important; }

  /* ヘッダー */
  .app-header {
    background: var(--primary); color: #fff; padding: 12px 16px 10px;
    position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 6px rgba(0,0,0,.12);
  }
  .header-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
  .header-top h1 { font-size: 17px; }
  .trip-bar { display: flex; gap: 8px; }
  .trip-bar select { flex: 1; min-width: 0; padding: 8px; font-size: 15px; border: none; border-radius: 8px; }
  .trip-period { font-size: 12px; opacity: .85; margin-top: 6px; }
  .btn-chip {
    background: rgba(255,255,255,.95); color: var(--primary); border: none; border-radius: 8px;
    padding: 7px 10px; font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer;
  }

  .container { max-width: 640px; margin: 0 auto; padding: 14px; }
  .tab { display: none; }
  .tab.active { display: block; animation: fadein .18s ease-out; }
  @keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

  /* カード */
  .card {
    background: var(--card); border: 1px solid var(--border); border-radius: 12px;
    padding: 14px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.05); position: relative;
  }
  .card-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding-right: 40px; }
  .title { font-size: 16px; font-weight: 700; margin: 6px 0 2px; word-break: break-word; }
  .meta { font-size: 13px; color: var(--sub); line-height: 1.55; }
  .memo { white-space: pre-wrap; word-break: break-word; font-size: 13px; color: var(--sub); line-height: 1.55; margin-top: 4px; }
  .memo.clamp { max-height: 4.7em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }
  .link-more { background: none; border: none; color: var(--primary); font-size: 13px; font-weight: 600; padding: 4px 0; cursor: pointer; }
  .empty { text-align: center; color: var(--sub); font-size: 14px; padding: 24px 0; }

  .badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--primary-light); color: var(--primary); }
  .badge.husband { background: var(--husband-bg); color: var(--husband); }
  .badge.wife { background: var(--wife-bg); color: var(--wife); }
  .badge.gray { background: #eef0f2; color: var(--sub); }

  .day-head { font-size: 14px; font-weight: 700; color: var(--primary); margin: 16px 2px 8px; display: flex; align-items: center; gap: 8px; }
  .day-head::after { content: ""; flex: 1; height: 1px; background: var(--border); }
  .time { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

  /* ボタン */
  .btn {
    display: inline-flex; justify-content: center; align-items: center; gap: 4px;
    background: var(--primary); color: #fff; border: 1px solid var(--primary); border-radius: 10px;
    padding: 11px 16px; font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
  }
  .btn:active { opacity: .8; }
  .btn-block { width: 100%; margin-top: 4px; }
  .btn-outline { background: #fff; color: var(--primary); }
  .btn-link { display: inline-block; margin-top: 8px; padding: 6px 12px; font-size: 13px; border-radius: 8px; border: 1px solid var(--primary); color: var(--primary); text-decoration: none; }
  .btn-del {
    position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%;
    border: none; background: transparent; font-size: 16px; cursor: pointer; opacity: .55;
  }
  .btn-del:active { background: #fdecea; opacity: 1; }

  /* 入力 */
  label { display: block; font-size: 12px; font-weight: 600; color: var(--sub); margin-bottom: 10px; }
  input, select, textarea {
    display: block; width: 100%; margin-top: 4px; padding: 10px; font-size: 16px; /* 16px未満だとiPhoneで拡大される */
    border: 1px solid #ccd2d6; border-radius: 8px; background: #fff; color: var(--text); font-family: inherit;
  }
  input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
  .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .add-card summary { font-weight: 700; font-size: 15px; color: var(--primary); cursor: pointer; list-style: none; }
  .add-card summary::-webkit-details-marker { display: none; }
  .add-card[open] summary { margin-bottom: 12px; }

  /* 集計 */
  .summary { background: var(--primary-light); border: 1px solid var(--primary); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
  .summary .big { font-size: 18px; font-weight: 700; color: var(--primary); }
  .summary .result { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--primary); font-size: 16px; font-weight: 700; color: var(--primary); }
  .progress { height: 8px; background: #fff; border-radius: 99px; overflow: hidden; margin-top: 8px; }
  .progress > div { height: 100%; background: var(--primary); transition: width .3s; }

  /* ToDo */
  .todo { display: flex; align-items: center; gap: 12px; cursor: pointer; padding-right: 50px; }
  .check { width: 26px; height: 26px; border-radius: 7px; border: 2px solid #b8c0c6; flex-shrink: 0; display: grid; place-items: center; color: #fff; font-size: 16px; }
  .todo.done .check { background: var(--primary); border-color: var(--primary); }
  .todo.done .title { text-decoration: line-through; color: #999; }
  .group-head { font-size: 13px; font-weight: 700; color: var(--sub); margin: 14px 2px 6px; }

  /* 写真 */
  .photo-grid { display: grid; gap: 12px; }
  .photo-card img { width: 100%; max-height: 360px; object-fit: cover; border-radius: 8px; margin-top: 8px; background: #eee; display: block; }
  .photo-frame { margin-top: 8px; border-radius: 8px; background: #eef0f2; min-height: 180px; display: grid; place-items: center; overflow: hidden; cursor: zoom-in; }
  .photo-frame img { margin-top: 0; }
  .photo-frame .ph { font-size: 13px; color: var(--sub); }
  .viewer { position: fixed; inset: 0; z-index: 450; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; animation: fadein .15s; }
  .viewer-body { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; padding: 12px; }
  .viewer img { max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 4px; }
  .viewer-caption { color: #eee; font-size: 14px; text-align: center; white-space: pre-wrap; }
  .viewer-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 40px; height: 40px; border-radius: 50%; border: none; background: rgba(255,255,255,.15); color: #fff; font-size: 18px; cursor: pointer; }

  /* 下のタブ */
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 100; background: #fff; border-top: 1px solid var(--border);
    display: flex; padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar button {
    flex: 1; background: none; border: none; color: var(--sub); font-size: 11px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
  }
  .tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .7; transition: .15s; }
  .tabbar button.active { color: var(--primary); font-weight: 700; }
  .tabbar button.active span { filter: none; opacity: 1; transform: translateY(-1px); }

  /* モーダル・ローダー・トースト */
  .modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 300; display: flex; align-items: flex-end; justify-content: center; }
  .modal-card { background: #fff; width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); animation: slideup .2s ease-out; }
  @media (min-width: 600px) { .modal-bg { align-items: center; } .modal-card { border-radius: 16px; } }
  @keyframes slideup { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
  .modal-title { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
  .modal-card { max-height: 92vh; overflow-y: auto; }
  .btn-danger-text { display: block; width: 100%; margin-top: 14px; padding: 10px; background: none; border: none; color: var(--danger); font-size: 14px; font-weight: 600; cursor: pointer; }
  .btn-danger-text:active { background: #fdecea; border-radius: 8px; }
  .btn-edit { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); width: 38px; height: 38px; border-radius: 50%; border: none; background: transparent; font-size: 16px; cursor: pointer; opacity: .6; }
  .btn-edit:active { background: var(--primary-light); opacity: 1; }
  .card.tappable { cursor: pointer; transition: transform .08s; }
  .card.tappable:active { transform: scale(.985); background: #fafbfb; }
  .edit-hint { position: absolute; top: 12px; right: 12px; font-size: 13px; opacity: .35; }
  .loader { position: fixed; inset: 0; background: rgba(255,255,255,.6); z-index: 400; display: grid; place-items: center; }
  .spinner { width: 40px; height: 40px; border: 4px solid var(--primary-light); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  .toast {
    position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    background: rgba(34,34,34,.92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
    z-index: 500; max-width: calc(100% - 32px); text-align: center; animation: fadein .2s;
  }
  .toast.error { background: rgba(201,48,44,.95); }

  /* 合言葉画面 */
  .login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
  .login-card { background: #fff; border-radius: 16px; padding: 28px 20px; width: 100%; max-width: 360px; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.08); }
  .login-icon { font-size: 40px; }
  .login-card h1 { font-size: 20px; margin: 8px 0 4px; color: var(--primary); }
  .login-card form { margin-top: 16px; }
