:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --text: #1d211f;
  --muted: #7a817d;
  --line: #e3e6e1;
  --accent: #16805a;
  --accent-soft: #e2f2ea;
  --on-accent: #ffffff;
  --danger: #c8372d;
  --bar-h: 120px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --surface: #1c201e;
    --text: #e8ebe9;
    --muted: #8d958f;
    --line: #2b302d;
    --accent: #3dbb87;
    --accent-soft: #1d3a2d;
    --on-accent: #0d1f17;
    --danger: #ff6b5e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* ヘッダー */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.top-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
}
h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}
.clear-btn {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
}

/* リスト */
.list {
  max-width: 600px;
  margin: 0 auto;
  padding: 4px 16px calc(var(--bar-h) + 20px);
}
.store { margin: 10px 0 22px; }
.store-name {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 4px 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.store-name .count { font-weight: 500; font-size: 13px; }

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
}
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 13px 16px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background-color .15s;
}
.item:first-child { border-top: none; }
.item.pressing { background: var(--line); }
.item.added { animation: added .8s ease-out; }

.check {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  display: grid;
  place-items: center;
}
.item.done .check {
  background: var(--accent);
  border-color: var(--accent);
}
.item.done .check::after {
  content: "";
  width: 6px;
  height: 11px;
  border: solid var(--on-accent);
  border-width: 0 2.5px 2.5px 0;
  transform: translateY(-1px) rotate(45deg);
}
.name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item.done .name {
  color: var(--muted);
  text-decoration: line-through;
}

.empty {
  margin-top: 25vh;
  text-align: center;
  color: var(--muted);
  line-height: 1.9;
}

/* 下部の入力バー */
.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 10px 0 calc(env(safe-area-inset-bottom) + 10px);
}
.bar-inner { max-width: 600px; margin: 0 auto; }

.stores {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 10px;
  scrollbar-width: none;
}
.stores::-webkit-scrollbar { display: none; }

.store-btn {
  flex: none;
  padding: 8px 15px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 15px;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.store-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.store-btn.add {
  color: var(--accent);
  font-weight: 700;
}
.store-btn.pressing { opacity: .55; }

.add-form {
  display: flex;
  gap: 8px;
  padding: 0 16px;
}
.add-form input,
.dialog input {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 17px; /* 16px未満だとiPhoneで勝手に拡大される */
  outline: none;
}
.add-form input:focus,
.dialog input:focus { border-color: var(--accent); }
.add-form button {
  flex: none;
  padding: 0 18px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}
.add-form button:disabled { opacity: .4; }

/* メニュー（下から出る） */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(0, 0, 0, .35);
  animation: fade .15s ease-out;
}
.sheet {
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  padding: 6px 10px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  animation: up .2s ease-out;
}
.sheet-title {
  padding: 12px 16px 8px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}
.sheet-btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 12px;
  background: none;
  font-size: 17px;
}
.sheet-btn:active { background: var(--line); }
.sheet-btn:disabled { opacity: .3; }
.sheet-btn.danger { color: var(--danger); font-weight: 600; }
.sheet-btn.cancel {
  margin-top: 6px;
  background: var(--bg);
  font-weight: 600;
}

/* 文字入力ダイアログ（キーボードに隠れないよう上寄せ） */
.overlay.dialog-overlay {
  justify-content: flex-start;
  padding: calc(env(safe-area-inset-top) + 60px) 16px 0;
}
.dialog {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 18px;
  background: var(--surface);
  border-radius: 16px;
  animation: pop .18s ease-out;
}
.dialog h2 {
  margin: 0 0 12px;
  font-size: 17px;
}
.dialog .row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.dialog .row button {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  font-weight: 600;
}
.dialog .row button.primary {
  background: var(--accent);
  color: var(--on-accent);
}

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
@keyframes added { from { background: var(--accent-soft); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
