/* ============================================================
   Tokens
   --accent は JS でグループカラーに差し替わる
   ============================================================ */
:root {
  --accent: #4f5bd5;
  --on-accent: #ffffff;
}

/* 派生色。.themed（集計カードなど）で --accent を上書きしたときも再計算されるよう両方に定義 */
:root, .themed {
  --accent-ink: color-mix(in srgb, var(--accent) 58%, #1a1a1f); /* 黄色など明るい色でも白地で読める濃さ */
  --accent-soft: color-mix(in srgb, var(--accent) 9%, var(--surface));
  --accent-line: color-mix(in srgb, var(--accent) 30%, var(--border));
}

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d22;
  --muted: #6e6e78;
  --border: #e3e3e8;
  --danger: #c93a4a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 8px rgba(0, 0, 0, 0.03);

  --radius: 14px;
  --font: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --tabbar-h: 60px;

  font-family: var(--font);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #1c1c21;
    --text: #ececf0;
    --muted: #9a9aa6;
    --border: #2e2e36;
    --danger: #ff6b7a;
    --shadow: none;
    color-scheme: dark;
  }

  :root, .themed {
    --accent-ink: color-mix(in srgb, var(--accent) 70%, #ffffff);
  }
}

* { box-sizing: border-box; }

html { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  line-height: 1.6;
  background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  /* 半透明＋ぼかしだと iOS の上端のぼかしと重なって文字がにじむので、不透明にする */
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 3px 0 var(--accent);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-mark {
  width: 22px;
  height: 22px;
  flex: none;
}
.logo-mark .lm-disc { fill: var(--text); }
.logo-mark .lm-accent { fill: var(--accent); }
.logo-mark .lm-cut { fill: var(--surface); }

.header-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-group::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.header-group:empty { display: none; }

/* ============================================================
   Layout
   ============================================================ */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 14px;
  font-size: 0.95rem;
  font-weight: 700;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  row-gap: 0; /* 折り返したときは .field の下余白だけにして、縦の間隔をそろえる */
}
/* 片方の項目の下に候補ボタンがあるときは、入力欄の高さを上でそろえる */
.row.top { align-items: flex-start; }

.grow { flex: 1 1 200px; }
.date-field { flex: 0 1 170px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  min-width: 0;
}

.field > span {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

input, select {
  font: inherit;
  font-size: 16px; /* iOS のズーム防止 */
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

input[type="checkbox"] { width: auto; accent-color: var(--accent); }

/* iOS の日付欄は独自の見た目で高さがずれ、未入力だと空白になるのでそろえる */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-height: 46px;
  text-align: left;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
select { min-height: 46px; }

/* ============================================================
   Buttons / chips
   ============================================================ */
.btn {
  font: inherit;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, filter 0.15s;
}

.btn:hover { background: var(--bg); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn.primary:hover { filter: brightness(0.94); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.small { padding: 5px 12px; font-size: 0.85rem; }
.btn.big { padding: 12px 24px; font-size: 1rem; font-weight: 700; }
.btn.danger { color: var(--danger); }

.count-pill {
  background: color-mix(in srgb, var(--on-accent) 22%, transparent);
  border-radius: 6px;
  padding: 0 8px;
  font-size: 0.85rem;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.actions.left { justify-content: flex-start; }

.hint {
  font-size: 0.83rem;
  color: var(--muted);
  margin: 0 0 12px;
}
.actions + .hint { margin: 12px 0 0; }

.backup-reminder {
  /* 背景は色をつけず（ピンク系の背景になるのを避ける）、左の線だけグループカラーにする */
  border-left: 4px solid var(--accent);
}
.backup-reminder p { margin: 0 0 10px; font-size: 0.9rem; }

.hidden { display: none !important; }

.chip {
  font: inherit;
  font-size: 0.82rem;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover { background: var(--bg); }

.chip.active {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.icon-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.icon-btn:hover { background: var(--bg); }

/* ============================================================
   記録
   ============================================================ */
.release-hero {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 12px;
  margin: -2px 0 16px;
  border-radius: 12px;
  background: var(--bg);
  border-left: 3px solid var(--accent);
}

.release-hero .jacket-thumb { width: 56px; height: 56px; }

.release-hero .info { min-width: 0; flex: 1; }

.release-hero .group {
  font-size: 0.78rem;
  color: var(--muted);
}

.release-hero .title {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.release-hero .total {
  text-align: right;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.release-hero .total strong {
  display: block;
  font-size: 1.4rem;
  line-height: 1.2;
  color: var(--text);
}

.release-hero .total small { font-size: 0.75rem; font-weight: 500; margin-left: 2px; }

.quick-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: -6px 0 14px;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.quick-chips:empty { display: none; }

.group-presets { margin: 4px 0 0; }

.type-steppers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.stepper {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  background: var(--surface);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.stepper.has-qty {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stepper .name {
  font-weight: 700;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.stepper .so-far {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.stepper .controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
}

.stepper button {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  touch-action: manipulation;
}

.stepper button:active { background: var(--bg); }

.stepper button[data-step="1"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.stepper input {
  flex: 1;
  width: auto;
  min-width: 0;
  text-align: center;
  padding: 6px 2px;
  font-size: 1.2rem;
  font-weight: 700;
  border: none;
  background: transparent;
}

.stepper input:focus { box-shadow: none; }

/* 記録ボタンはタブバーのすぐ上に横幅いっぱいで固定する（sticky だとスクロールで動いて見えるため） */
.sticky-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 25;
  margin: 0;
  padding: 8px max(16px, calc((100% - 720px) / 2 + 16px));
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-wrap: nowrap;
}
.sticky-actions .btn { flex: 1; }
.sticky-actions .btn.ghost { flex: 0 0 auto; }

/* 固定ボタンの分だけ、記録タブの下に余白をとる */
#tab-record { padding-bottom: 72px; }

.sticky-actions .btn.primary {
  box-shadow: 0 4px 14px -4px rgba(0, 0, 0, 0.25);
}

.empty-state {
  text-align: center;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  margin-bottom: 14px;
}

.empty-state p { margin: 0 0 10px; color: var(--muted); }

/* ============================================================
   リリース
   ============================================================ */
.type-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.type-row {
  display: grid;
  grid-template-columns: 1fr 110px 36px;
  gap: 8px;
  align-items: center;
}

.preset-buttons { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  padding: 0;
  background: var(--c);
}

.swatch.active { box-shadow: 0 0 0 2px var(--text); }

.swatch-custom {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: conic-gradient(#e0605e, #e0c35e, #6ec27a, #5eb0e0, #7a6ee0, #d05ec0, #e0605e);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}

.swatch-custom.active { box-shadow: 0 0 0 2px var(--text); }

.swatch-custom input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  border: none;
}

.jacket-picker { display: flex; gap: 14px; align-items: center; }
.jacket-buttons { display: flex; gap: 6px; flex-wrap: wrap; }

.jacket-thumb {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--bg) center / cover no-repeat;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.jacket-thumb.placeholder::after {
  content: "";
  width: 50%;
  height: 50%;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: radial-gradient(circle, var(--muted) 0 8%, transparent 9%);
  opacity: 0.8;
}

.chip-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-list li {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 3px 3px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
}

.chip-list button {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 8px;
}

/* ============================================================
   Lists
   ============================================================ */
.history {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history li {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.history li:first-child { border-top: none; padding-top: 0; }

.history .body { flex: 1; min-width: 0; }

.history .meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.history .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c, var(--accent));
  margin-right: 6px;
  vertical-align: 1px;
}

.history .item-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.history .jacket-thumb { width: 44px; height: 44px; border-radius: 6px; }

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 0;
}

/* ============================================================
   集計
   ============================================================ */
.overview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.stat .label { font-size: 0.72rem; color: var(--muted); }

.stat .value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stat .value small { font-size: 0.75rem; font-weight: 500; margin-left: 2px; color: var(--muted); }

.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 14px;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.filter-chips .chip .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c);
  margin-right: 6px;
  vertical-align: 1px;
}

/* 月別グラフ */
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.year-nav { display: flex; align-items: center; gap: 2px; }
.year-nav h2 { margin: 0; min-width: 5.5em; text-align: center; }
.year-nav .icon-btn:disabled { opacity: 0.3; cursor: default; background: none; }

.chart-wrap { position: relative; }

.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart-wrap .grid { stroke: var(--border); stroke-width: 1; }
.chart-wrap .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-wrap .axis-label.now { fill: var(--text); font-weight: 700; }
.chart-wrap .bar { fill: var(--accent); transition: opacity 0.15s; }
.chart-wrap .hit { fill: transparent; cursor: pointer; }
.chart-wrap .col-hover { fill: var(--accent-soft); }

.chart-wrap.hovering .bar { opacity: 0.45; }
.chart-wrap.hovering .bar.active { opacity: 1; }

.chart-tip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  pointer-events: none;
  background: var(--text);
  color: var(--surface);
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  z-index: 2;
}

.chart-tip strong { display: block; font-size: 0.9rem; }

.year-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.year-summary strong { color: var(--text); font-variant-numeric: tabular-nums; }

.summary-card { border-left: 3px solid var(--accent); }

.summary-head {
  display: flex;
  gap: 14px;
  align-items: center;
}

.summary-head .info { flex: 1; min-width: 0; }

.summary-head .group {
  font-size: 0.78rem;
  color: var(--muted);
}

.summary-head h3 { margin: 2px 0 0; font-size: 1rem; font-weight: 700; }

.total-badge {
  text-align: right;
  flex-shrink: 0;
}

.total-badge strong {
  font-size: 1.8rem;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.total-badge span { font-size: 0.8rem; color: var(--muted); }

.type-bars { margin: 16px 0 8px; display: flex; flex-direction: column; gap: 8px; }

.type-bar {
  display: grid;
  grid-template-columns: minmax(80px, 30%) 1fr 52px;
  gap: 10px;
  align-items: center;
  font-size: 0.88rem;
}

.type-bar .track {
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}

.type-bar .fill {
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.type-bar .qty { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

details { margin-top: 8px; }
summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }

.venue-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 8px;
}

.venue-table td { padding: 5px 0; border-top: 1px solid var(--border); vertical-align: top; }
.venue-table td:last-child { text-align: right; padding-left: 8px; }

/* ============================================================
   Tab bar
   ============================================================ */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  padding: 4px 8px calc(env(safe-area-inset-bottom) + 4px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  max-width: 160px;
  height: calc(var(--tabbar-h) - 8px);
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}

.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.tab.active {
  color: var(--accent-ink);
  font-weight: 700;
}

/* ============================================================
   Dialog / toast
   ============================================================ */
dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.35);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.dialog-body { padding: 16px 18px 18px; }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dialog-head h2 { margin: 0; font-size: 1rem; font-weight: 700; }

.image-stage {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
  display: grid;
  place-items: center;
}

.image-stage img {
  display: block;
  max-width: 100%;
  max-height: 46vh;
  border-radius: 4px;
  box-shadow: 0 4px 16px -8px rgba(0, 0, 0, 0.35);
}

.editor .field { margin-bottom: 12px; }

.segmented {
  display: inline-flex;
  padding: 2px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  align-self: flex-start;
}

.segmented button {
  font: inherit;
  font-size: 0.85rem;
  border: none;
  background: none;
  color: var(--muted);
  padding: 5px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.9rem;
}

.toggles label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.toggles label.disabled { opacity: 0.45; cursor: default; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--surface);
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  opacity: 0;
  transition: transform 0.2s, opacity 0.2s;
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

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

@media (max-width: 420px) {
  main { padding: 12px; }
  .card { padding: 16px; }
  .type-steppers { grid-template-columns: repeat(2, 1fr); }
  .overview { gap: 8px; }
  .stat { padding: 10px; }
  .overview .stat .value { font-size: clamp(0.95rem, 5vw, 1.2rem); }
}
