/* ===== 変数 ===== */
:root {
  --bg:          #0D0D0D;
  --surface:     #1C1C1E;
  --surface-2:   #2C2C2E;
  --accent:      #9D5FFF;
  --accent-dim:  rgba(157, 95, 255, 0.15);
  --text:        #FFFFFF;
  --text-2:      #8E8E93;
  --danger:      #FF453A;
  --sep:         rgba(255, 255, 255, 0.08);
  --nav-h:       52px;
  --tab-h:       56px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== リセット ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ===== ナビゲーションバー ===== */
.nav-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: 20px;
  padding-right: 8px;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--sep);
  display: flex;
  align-items: center;
  z-index: 20;
}

.nav-title {
  flex: 1;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
  transition: background 0.1s;
}
.icon-btn:active { background: var(--accent-dim); }

/* ===== コンテンツエリア ===== */
.content-area {
  position: fixed;
  top: calc(var(--nav-h) + var(--safe-top));
  bottom: calc(var(--tab-h) + var(--safe-bottom));
  left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== 画面切替 ===== */
.screen { display: none; min-height: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ===== 空状態 ===== */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px 24px;
  color: var(--text-2);
}
.empty-text { font-size: 16px; }

/* ===== タスクリスト ===== */
.task-list {
  list-style: none;
  padding: 8px 0;
  flex: 1;
}

.task-row {
  display: flex;
  align-items: center;
  padding: 0 20px 0 16px;
  min-height: 60px;
  border-bottom: 1px solid var(--sep);
  transition: background 0.1s;
  gap: 4px;
  /* 長押しでのテキスト選択・コールアウトを防止 */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.task-row:active { background: var(--surface); }

.task-row-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 0;
  min-width: 0;
  cursor: pointer;
}

.task-name {
  font-size: 17px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.task-time {
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  flex-shrink: 0;
}

.task-menu-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
  flex-shrink: 0;
  transition: background 0.1s;
}
.task-menu-btn:active { background: var(--surface-2); }

/* ===== ボトムタブバー ===== */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--sep);
  display: flex;
  z-index: 20;
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
  transition: color 0.15s;
  min-height: 44px;
}
.tab-btn.active { color: var(--accent); }

/* ===== ボタン ===== */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary:not(:disabled):active { opacity: 0.8; }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-danger:active { opacity: 0.8; }

.confirm-message {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-line;
}

.btn-ghost {
  background: none;
  color: var(--text-2);
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 16px;
  cursor: pointer;
}
.btn-ghost:active { color: var(--text); }

/* ===== モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  /* キーボード表示時に入力欄が隠れないよう上寄せ */
  align-items: flex-start;
  justify-content: center;
  padding: 20vh 24px 24px;
}
.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modal-pop 0.2s ease;
}
@keyframes modal-pop {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
}

.input-wrap { position: relative; }

.text-input {
  width: 100%;
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 12px 48px 12px 14px;
  color: var(--text);
  font-size: 17px;
  outline: none;
  transition: border-color 0.15s;
}
.text-input::placeholder { color: var(--text-2); }
.text-input:focus { border-color: var(--accent); }

.char-counter {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-2);
  pointer-events: none;
}

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

/* ===== アクションシート ===== */
.action-sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.action-sheet.hidden { display: none; }

.sheet-overlay {
  flex: 1;
  background: rgba(0, 0, 0, 0.5);
}

.sheet-card {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.sheet-title {
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--sep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-action {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid var(--sep);
  color: var(--text);
  font-size: 17px;
  padding: 16px 20px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}
.sheet-action:active { background: var(--surface-2); }
.sheet-action.danger { color: var(--danger); }
.sheet-action.cancel { color: var(--text-2); border-bottom: none; }

/* ===== モード選択シート ===== */
.mode-pomodoro {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.mode-desc {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 400;
  margin-left: auto;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sep);
}

.preset-btn {
  background: var(--surface-2);
  color: var(--text);
  border: none;
  border-radius: 12px;
  padding: 14px 0;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: background 0.1s;
}
.preset-btn:active { background: var(--accent-dim); }

/* ===== タイマー画面 ===== */
.timer-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  transition: background 0.5s ease;
}

/* 休憩中は背景をインディゴ系に */
body.timer-break .timer-overlay {
  background: #16163a;
}

.timer-header {
  display: flex;
  align-items: center;
  height: var(--nav-h);
  padding: 0 8px;
}

.timer-cancel-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  padding: 10px 12px;
  min-height: 44px;
  cursor: pointer;
  flex-shrink: 0;
}

.timer-task-name {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 4px;
}

.timer-header-spacer {
  width: 76px; /* キャンセルボタンと同幅でタイトルを中央に */
  flex-shrink: 0;
}

.timer-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 20px;
}

/* セット進捗 */
.set-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.set-dots { display: flex; gap: 10px; }

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface-2);
}
.dot.filled { background: var(--accent); }
.dot.active {
  background: var(--accent-dim);
  border: 2px solid var(--accent);
}

.set-label {
  font-size: 14px;
  color: var(--text-2);
}

/* 円形プログレスリング */
.ring-wrap {
  position: relative;
  width: 260px;
  height: 260px;
}

.ring { transform: rotate(-90deg); }

.ring-bg {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 10;
}

.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 741.4; /* 2π × 118 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.25s linear, stroke 0.5s;
}
body.timer-break .ring-fg { stroke: #6E6CFF; }

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.time-display {
  font-size: 60px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}

.phase-label {
  font-size: 15px;
  color: var(--text-2);
}

/* タイマー操作ボタン */
.timer-controls {
  display: flex;
  gap: 16px;
  min-height: 52px;
}

.ctrl-btn {
  background: var(--surface);
  color: var(--text);
  border: none;
  border-radius: 26px;
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  min-height: 52px;
  min-width: 130px;
  cursor: pointer;
  transition: background 0.1s;
}
.ctrl-btn:active { background: var(--surface-2); }

/* ===== 完了画面 ===== */
.complete-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.complete-emoji { font-size: 56px; margin-bottom: 8px; }

.complete-title {
  font-size: 22px;
  font-weight: 700;
}

.complete-task {
  font-size: 16px;
  color: var(--text-2);
  margin-top: 12px;
  max-width: 80vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.complete-minutes {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

.complete-sets {
  font-size: 15px;
  color: var(--text-2);
}

.complete-home-btn {
  margin-top: 28px;
  min-width: 200px;
  min-height: 50px;
}

/* ===== 統計画面 ===== */

.seg-control {
  display: flex;
  gap: 4px;
  margin: 12px 16px 4px;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 8px;
  cursor: pointer;
  min-height: 36px;
  transition: background 0.15s, color 0.15s;
}
.seg-btn.active {
  background: var(--surface-2);
  color: var(--text);
}

.stats-section {
  padding: 16px 16px 4px;
}

.stats-heading-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.stats-heading {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
}

.chart-total {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

/* 棒グラフ */
.chart {
  background: var(--surface);
  border-radius: 14px;
  padding: 16px 10px 8px;
  min-height: 160px;
  display: flex;
  align-items: stretch;
}

.chart-bars {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 140px;
  position: relative; /* グリッド線の基準 */
}

/* 縦軸グリッド（棒の描画領域＝ラベル帯16pxを除いた範囲に重ねる） */
.chart-grid {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 16px;
  pointer-events: none;
}

.grid-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.10);
}

.grid-label {
  position: absolute;
  right: 0;
  top: -13px;
  font-size: 9px;
  color: var(--text-2);
  background: var(--surface);
  padding-left: 4px;
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  min-width: 0;
}

/* 棒の描画領域をラベルと分離し、height% の線形性を保証する */
.bar-area {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

.bar {
  width: 70%;
  max-width: 22px;
  display: flex;
  flex-direction: column;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
}
/* 記録があるのに見えない棒を防ぐ */
.bar:not(:empty) { min-height: 3px; }

.bar-seg { width: 100%; }

.col-label {
  font-size: 9px;
  color: var(--text-2);
  margin-top: 4px;
  height: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.chart-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-size: 14px;
}

/* 凡例 */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 10px 4px 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-2);
}
.legend-item.deleted { opacity: 0.5; }

.legend-chip {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* タスク別累計ランキング */
.ranking {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rank-row.deleted { opacity: 0.5; }

.rank-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}

.rank-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-tag {
  font-size: 10px;
  color: var(--text-2);
  margin-left: 6px;
}

.rank-time {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  flex-shrink: 0;
}

.rank-bar-bg {
  height: 6px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
}

.rank-bar {
  height: 100%;
  border-radius: 3px;
}

.ranking-empty {
  color: var(--text-2);
  font-size: 14px;
  padding: 8px 0;
}

/* ===== データ管理 ===== */
.data-section { padding-bottom: 32px; }

.data-actions {
  display: flex;
  gap: 10px;
}

.btn-secondary {
  flex: 1;
  background: var(--surface);
  color: var(--text);
  border: none;
  border-radius: 12px;
  padding: 13px 0;
  font-size: 15px;
  font-weight: 600;
  min-height: 48px;
  cursor: pointer;
  transition: background 0.1s;
}
.btn-secondary:active { background: var(--surface-2); }

.data-note {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
  margin-top: 10px;
}

/* ===== セッション記録一覧 ===== */
.session-log {
  list-style: none;
  padding: 8px 0 24px;
}

.log-date {
  padding: 18px 20px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.log-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--sep);
}
.log-row.cancelled { opacity: 0.45; }

.log-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.log-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-meta {
  font-size: 12px;
  color: var(--text-2);
}

.log-minutes {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

/* ===== その他 ===== */
.hidden { display: none !important; }

.placeholder-msg {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-2);
  font-size: 15px;
}
