:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #e5e5ea;
  --text: #1c1c1e;
  --sub: #6e6e73;
  --line: rgba(60, 60, 67, 0.18);
  --accent: #e5533d;
  --on-accent: #ffffff;
  --break: #2fa35a;
  --danger: #e0352b;
  --pressed: rgba(0, 0, 0, 0.07);
  --backdrop: rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --ring-track: #e5e5ea;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f2f2f7;
    --sub: #98989f;
    --line: rgba(84, 84, 88, 0.6);
    --accent: #ff6a52;
    --break: #3cc46d;
    --danger: #ff453a;
    --pressed: rgba(255, 255, 255, 0.09);
    --backdrop: rgba(0, 0, 0, 0.55);
    --shadow: none;
    --ring-track: #2c2c2e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Segoe UI", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
[hidden] { display: none !important; }

#app { height: 100%; display: flex; flex-direction: column; }
#views { flex: 1; min-height: 0; position: relative; }
.tab-view { position: absolute; inset: 0; }

/* ---------- 画面・ヘッダー ---------- */
.screen { height: 100%; display: flex; flex-direction: column; }

.hdr {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  padding: calc(env(safe-area-inset-top) + 6px) calc(env(safe-area-inset-right) + 8px) 6px calc(env(safe-area-inset-left) + 14px);
  flex-shrink: 0;
}
.hdr-back {
  width: 36px; height: 36px; margin-left: -10px;
  display: grid; place-items: center;
  color: var(--accent); border-radius: 50%;
}
.hdr-back svg { width: 22px; height: 22px; }
.hdr-title {
  flex: 1; min-width: 0; margin: 0;
  font-size: 20px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hdr-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%; color: var(--accent); font-size: 20px; line-height: 1;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active, .hdr-back:active { background: var(--pressed); }

.chips {
  display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
  padding: 2px calc(env(safe-area-inset-right) + 12px) 8px calc(env(safe-area-inset-left) + 12px);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 6px 14px; border-radius: 999px;
  background: var(--surface-2); font-size: 14px; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.screen-body {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 4px calc(env(safe-area-inset-right) + 12px) 24px calc(env(safe-area-inset-left) + 12px);
}

/* ---------- カード ---------- */
.card-list { position: relative; }
.card {
  display: flex; align-items: stretch;
  background: var(--surface); border-radius: 12px; margin-bottom: 8px;
  box-shadow: var(--shadow);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  cursor: pointer;
}
.card.pressed { box-shadow: inset 0 0 0 999px var(--pressed); }
.card-main { flex: 1; min-width: 0; padding: 10px 14px; }
.card-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub {
  margin-top: 2px; color: var(--sub); font-size: 14px; min-height: 1.3em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-meta { margin-top: 4px; color: var(--sub); font-size: 12px; }
.card-icon { display: grid; place-items: center; padding-left: 14px; font-size: 22px; }
.card-side { display: flex; align-items: center; gap: 6px; padding-right: 14px; color: var(--sub); font-size: 14px; }
.handle {
  width: 44px; flex-shrink: 0;
  display: grid; place-items: center;
  color: var(--sub); font-size: 18px;
  touch-action: none; cursor: grab;
}
.more-btn { width: 44px; flex-shrink: 0; color: var(--sub); font-size: 20px; }
.dragging { position: relative; z-index: 5; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25) !important; }
.empty { text-align: center; color: var(--sub); padding: 48px 16px; line-height: 1.8; }

/* ---------- フォーム ---------- */
.form { display: flex; flex-direction: column; gap: 14px; padding-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--sub); padding-left: 4px; }
.input {
  width: 100%;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px;
}
textarea.input { resize: vertical; min-height: 180px; line-height: 1.5; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-error { color: var(--danger); margin: 0; font-size: 14px; }
.btn-primary {
  background: var(--accent); color: var(--on-accent);
  border-radius: 12px; padding: 13px; font-weight: 600; font-size: 17px;
}
.btn-primary:active { opacity: 0.8; }

/* ---------- 設定リスト ---------- */
.section-title { font-size: 13px; color: var(--sub); margin: 22px 4px 6px; }
.section-title:first-child { margin-top: 4px; }
.list { background: var(--surface); border-radius: 12px; overflow: hidden; position: relative; }
.row { display: flex; align-items: center; min-height: 48px; width: 100%; background: var(--surface); text-align: left; }
.row + .row { border-top: 0.5px solid var(--line); }
.row-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 12px 14px; text-align: left; }
.row-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-label.pad { padding: 12px 14px; }
.row-note { color: var(--sub); font-size: 14px; white-space: nowrap; }
.row-note.pad { padding-right: 14px; }
.row-icon { width: 44px; height: 44px; flex-shrink: 0; font-size: 16px; }
.row-input {
  width: 84px; margin-right: 14px;
  font: inherit; font-size: 16px; text-align: right;
  color: var(--accent); background: transparent; border: 0;
}
.row-input:focus { outline: none; }
.row-link { padding: 12px 14px; color: var(--accent); }
.row-link.danger { color: var(--danger); }
.row-link:active, .row-main:active { background: var(--pressed); }
.note { font-size: 13px; color: var(--sub); margin: 6px 4px 0; line-height: 1.6; }

/* ---------- アクションシート・ダイアログ ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  background: var(--backdrop);
  animation: fade-in 0.15s ease-out;
}
.backdrop.center { align-items: center; }
.sheet {
  width: 100%; max-width: 560px;
  padding: 8px calc(env(safe-area-inset-right) + 8px) calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 8px);
  animation: slide-up 0.2s ease-out;
}
.sheet-group { background: var(--surface); border-radius: 14px; overflow: hidden; margin-top: 8px; }
.sheet-title {
  padding: 12px 16px; text-align: center; color: var(--sub); font-size: 13px;
  white-space: pre-line; overflow-wrap: anywhere;
}
.sheet-btn { display: block; width: 100%; padding: 16px; font-size: 17px; color: var(--accent); text-align: center; }
.sheet-title + .sheet-btn, .sheet-btn + .sheet-btn { border-top: 0.5px solid var(--line); }
.sheet-btn:active { background: var(--pressed); }
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { font-weight: 600; }

.dialog {
  width: min(320px, 86vw);
  background: var(--surface); border-radius: 14px;
  padding: 18px 16px 0;
  display: flex; flex-direction: column; gap: 12px;
  animation: pop-in 0.15s ease-out;
}
.dialog-title { font-weight: 600; text-align: center; }
.dialog-message { text-align: center; font-size: 15px; line-height: 1.6; white-space: pre-line; overflow-wrap: anywhere; }
.dialog-actions { display: flex; margin: 4px -16px 0; border-top: 0.5px solid var(--line); }
.dialog-actions button { flex: 1; padding: 13px; color: var(--accent); font-size: 17px; }
.dialog-actions button + button { border-left: 0.5px solid var(--line); }
.dialog-actions button:active { background: var(--pressed); }
.dialog-actions .strong { font-weight: 600; }
.dialog-actions .danger { color: var(--danger); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }
@keyframes pop-in { from { transform: scale(1.08); opacity: 0; } }

/* ---------- トースト・更新バナー ---------- */
#toast {
  position: fixed; left: 50%; z-index: 200;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  transform: translate(-50%, 12px);
  max-width: 86vw; padding: 10px 18px; border-radius: 999px;
  background: rgba(40, 40, 44, 0.92); color: #fff; font-size: 15px; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#update-banner {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 150;
  top: calc(env(safe-area-inset-top) + 8px);
  padding: 10px 18px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

/* ---------- タブバー ---------- */
.tabbar {
  display: flex; flex-shrink: 0;
  background: var(--surface); border-top: 0.5px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tab-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 6px 0 4px; font-size: 11px; color: var(--sub);
}
.tab-icon { font-size: 22px; line-height: 1.15; filter: grayscale(1); opacity: 0.55; }
.tab-btn[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.tab-btn[aria-selected="true"] .tab-icon { filter: none; opacity: 1; }

/* ---------- メモ編集 ---------- */
.screen-body.editor-body { padding: 0; display: flex; overflow: hidden; }
.memo-editor {
  flex: 1; width: 100%;
  border: 0; outline: 0; resize: none;
  background: transparent; color: var(--text);
  font: inherit; font-size: 17px; line-height: 1.6;
  padding: 4px calc(env(safe-area-inset-right) + 16px) 40px calc(env(safe-area-inset-left) + 16px);
}

/* ---------- ポモドーロ ---------- */
.pomo {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding-bottom: 16px;
  --phase-color: var(--accent);
}
.pomo[data-phase="short"], .pomo[data-phase="long"] { --phase-color: var(--break); }
.pomo-phase {
  font-size: 17px; font-weight: 700;
  padding: 5px 16px; border-radius: 999px;
  background: var(--phase-color); color: #fff;
}
.pomo-ring { position: relative; width: min(72vw, 300px); aspect-ratio: 1; }
.pomo-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--ring-track); stroke-width: 5; }
.ring-progress {
  fill: none; stroke: var(--phase-color); stroke-width: 5; stroke-linecap: round;
  transition: stroke-dashoffset 0.25s linear;
}
.pomo-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.pomo-time { font-size: clamp(44px, 16vw, 66px); font-weight: 300; font-variant-numeric: tabular-nums; }
.pomo-round { font-size: 16px; color: var(--sub); }
.pomo-controls { display: flex; align-items: center; gap: 28px; }
.pomo-main {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--phase-color); color: #fff; font-size: 17px; font-weight: 700;
}
.pomo-skip { width: 64px; height: 64px; border-radius: 50%; background: var(--surface-2); font-size: 14px; }
.pomo-main:active, .pomo-skip:active { opacity: 0.8; }
.pomo-note { min-height: 3.2em; margin: 0; padding: 0 20px; color: var(--sub); font-size: 14px; line-height: 1.6; text-align: center; white-space: pre-line; }
