/* =============================================
   CSS変数 & テーマ定義
   ============================================= */
:root {
  --font-main: 'Outfit', 'Noto Sans JP', sans-serif;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --transition: 0.3s ease;
}

/* 時間帯テーマ（白ベース・超薄い色調） */
body.morning {
  --bg-tint: rgba(255, 200, 120, 0.22);
  --bg-solid: #fdf8f2;
  --text-primary: #1a1206;
  --text-secondary: #7a6040;
  --card-bg: rgba(255, 255, 255, 0.82);
  --card-border: rgba(200, 160, 80, 0.18);
  --accent: #d4870a;
  --accent2: #f0a500;
  --chip-bg: rgba(255, 185, 60, 0.12);
  --chip-border: rgba(200, 140, 40, 0.2);
}
body.noon {
  --bg-tint: rgba(100, 190, 240, 0.18);
  --bg-solid: #f4f9fd;
  --text-primary: #0a1e2e;
  --text-secondary: #3a6080;
  --card-bg: rgba(255, 255, 255, 0.84);
  --card-border: rgba(80, 160, 210, 0.18);
  --accent: #0878c8;
  --accent2: #00a8b5;
  --chip-bg: rgba(60, 160, 220, 0.10);
  --chip-border: rgba(40, 130, 200, 0.2);
}
body.evening {
  --bg-tint: rgba(240, 130, 60, 0.18);
  --bg-solid: #fdf5f0;
  --text-primary: #1a0800;
  --text-secondary: #7a4020;
  --card-bg: rgba(255, 255, 255, 0.83);
  --card-border: rgba(210, 120, 50, 0.18);
  --accent: #c9530a;
  --accent2: #e08010;
  --chip-bg: rgba(230, 110, 40, 0.10);
  --chip-border: rgba(200, 90, 20, 0.2);
}
body.night {
  --bg-tint: rgba(80, 100, 160, 0.20);
  --bg-solid: #f2f3f8;
  --text-primary: #101828;
  --text-secondary: #4a5578;
  --card-bg: rgba(255, 255, 255, 0.80);
  --card-border: rgba(100, 120, 180, 0.16);
  --accent: #5a5fcf;
  --accent2: #0097b5;
  --chip-bg: rgba(90, 110, 190, 0.10);
  --chip-border: rgba(80, 100, 180, 0.2);
}

/* =============================================
   リセット & ベース
   ============================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  font-family: var(--font-main);
  color: var(--text-primary);
  overflow: hidden;
}

body {
  background-color: var(--bg-solid);
  background-image: radial-gradient(ellipse at 60% 10%, var(--bg-tint) 0%, transparent 70%);
  transition: background-color 2s ease, background-image 2s ease;
}

/* =============================================
   アプリコンテナ（縦長16:9）
   ============================================= */
#app {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(100vw, calc(100vh * 9 / 16));
  height: min(100vh, calc(100vw * 16 / 9));
  max-width: 480px;
  max-height: 853px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow-y: auto;
  scrollbar-width: none;
}
#app::-webkit-scrollbar { display: none; }

/* =============================================
   共通カード
   ============================================= */
section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

/* =============================================
   固定費セクション
   ============================================= */
#fixed-costs {
  padding: 14px 16px 12px;
}

/* 上段: ラベル + 総額 */
.fixed-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}
.fixed-header-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  white-space: nowrap;
}
#fixed-total {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1;
}
.fixed-total-unit {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 1px;
}

/* 下段: アイコンチップ横並び */
.fixed-chips {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.fixed-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 10px;
  padding: 6px 4px;
  cursor: pointer;
  transition: background var(--transition), transform 0.15s ease;
  flex: 1;
  min-width: 38px;
}
.fixed-chip:hover {
  background: rgba(0,0,0,0.05);
  transform: translateY(-1px);
}
.chip-icon {
  width: 20px;
  height: 20px;
  color: var(--accent);
  flex-shrink: 0;
}
.chip-label { font-size: 0.5rem; color: var(--text-secondary); white-space: nowrap; line-height: 1; }
.chip-amount { font-size: 0.6rem; font-weight: 700; color: var(--text-primary); white-space: nowrap; }
.chip-input {
  width: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.6rem;
  font-weight: 700;
  text-align: center;
  padding: 0;
  -moz-appearance: textfield;
}
.chip-input::-webkit-outer-spin-button,
.chip-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.chip-inactive {
  opacity: 0.35;
  filter: grayscale(1);
  pointer-events: none;
}

/* =============================================
   カレンダーセクション
   ============================================= */
#calendar-section {
  padding: 10px 12px;
  flex: 1;
}

.calendar-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
#calendar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}
.nav-btn {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1.1rem;
  width: 28px;
  height: 28px;
  cursor: pointer;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-btn:hover { background: rgba(0,0,0,0.07); }

.weekday-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.weekday-header span:first-child { color: #e05050; }
.weekday-header span:last-child  { color: #4080cc; }

#calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

/* カレンダー日付セル */
.day-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: default;
  position: relative;
  border: 1px solid transparent;
  padding: 2px;
  transition: transform 0.15s ease;
}
.day-cell .day-num {
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}
.day-cell .day-cost {
  font-size: 0.48rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

/* 状態別カラー */
.day-cell.empty {
  opacity: 0;
  pointer-events: none;
}
.day-cell.no-data {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.06);
  color: var(--text-primary);
}
/* 過去日・データ未入力 */
.day-cell.no-data-past {
  background: rgba(0,0,0,0.02);
  border-color: rgba(0,0,0,0.08);
  color: var(--text-secondary);
  opacity: 0.6;
}
.day-cost.no-entry {
  opacity: 0.4;
}
.day-cell.goal-ok {
  background: linear-gradient(135deg, rgba(46,204,130,0.28), rgba(0,192,168,0.22));
  border-color: rgba(0,190,140,0.35);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0,180,130,0.12);
}
.day-cell.goal-ng {
  background: linear-gradient(135deg, rgba(224,80,80,0.22), rgba(224,112,64,0.18));
  border-color: rgba(210,60,60,0.28);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(200,60,60,0.10);
}
.day-cell.today {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.day-cell.sunday .day-num { color: #cc3333; }
.day-cell.saturday .day-num { color: #2266cc; }
/* goal-ok/ng の sunday/saturday 上書き（淡色背景なので元色を維持） */
.day-cell.goal-ok .day-num { color: #1a7a55; }
.day-cell.goal-ng .day-num { color: #a03030; }

/* =============================================
   サマリーセクション
   ============================================= */
#summary-section {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-top {
  display: flex;
  justify-content: space-around;
}
.summary-item { text-align: center; }
.summary-label { font-size: 0.62rem; color: var(--text-secondary); display: block; margin-bottom: 2px; }
.summary-value { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); display: block; }

/* 目標バー */
.goal-bar-wrap { display: flex; flex-direction: column; gap: 4px; }
.goal-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-secondary);
}
.goal-bar-label strong { color: var(--text-primary); }
.goal-bar-track {
  height: 7px;
  background: rgba(0,0,0,0.07);
  border-radius: 99px;
  overflow: hidden;
}
.goal-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #2ecc82, #00c0a8);
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1), background 0.4s;
  width: 0%;
}
.goal-bar-fill.over { background: linear-gradient(90deg, #e05050, #e07040); }

/* 月次目標 自動計算ヒント */
.goal-hint {
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0;
}
.input-wrap--auto input {
  color: var(--text-secondary);
  font-style: italic;
}

/* GASメタ情報 */
.gas-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 4px 0;
  font-size: 0.62rem;
  color: var(--text-secondary);
}
.gas-auto-label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}
.gas-auto-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 12px;
  height: 12px;
}

/* 目標設定 */
.goal-settings h3,
.gas-section h3 {
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.goal-inputs {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}
.goal-inputs label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.63rem;
  color: var(--text-secondary);
}
.input-wrap {
  display: flex;
  align-items: center;
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 5px 9px;
}
.yen-sign { font-size: 0.72rem; color: var(--text-secondary); margin-right: 4px; }
.input-wrap input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  width: 100%;
}
.input-wrap input::placeholder { color: var(--text-secondary); opacity: 0.6; }

/* ボタン */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 7px 18px;
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  letter-spacing: 0.04em;
}
.btn-primary:hover { opacity: 0.85; transform: translateY(-1px); }

.btn-secondary {
  background: rgba(0,0,0,0.06);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.78rem;
  padding: 6px 12px;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}
.btn-secondary:hover { background: rgba(0,0,0,0.10); }

.btn-danger {
  background: rgba(214, 48, 49, 0.12);
  border: 1px solid rgba(214, 48, 49, 0.35);
  border-radius: 8px;
  color: #d63031;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}
.btn-danger:hover { background: rgba(214, 48, 49, 0.22); }

/* データ管理行 */
.data-manage {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--card-border);
}
.data-manage-note {
  font-size: 0.72rem;
  color: var(--text-secondary);
  opacity: 0.75;
}

/* GASセクション */
.gas-input-wrap {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}
.gas-input-wrap input {
  flex: 1;
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.72rem;
  outline: none;
}
.gas-input-wrap input::placeholder { color: var(--text-secondary); opacity: 0.7; }

#gas-status {
  font-size: 0.65rem;
  color: var(--text-secondary);
  min-height: 1em;
}
