:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e1eb;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --soft: #eaf1ff;
  --danger: #dc2626;
  --done: #16a34a;
  --warn: #b45309;
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }

button, .file-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
}
button:disabled, input:disabled { cursor: not-allowed; opacity: 0.55; }
button:active, .file-button:active { transform: translateY(1px); }

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.05; }
h2 { font-size: 17px; line-height: 1.2; }
.ghost-button { width: 44px; border-radius: 50%; }

main { display: grid; gap: 14px; }

.list-panel, .history-panel, .backup-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.quick-add { display: flex; gap: 8px; }
input {
  min-height: 44px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}
.quick-add input[type="text"] { flex: 1; }
.quick-add button, .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.text-button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
}
.running-note { color: var(--warn); font-size: 13px; font-weight: 900; }

.todo-list, .history-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.todo-card, .history-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.todo-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}
.todo-card.done { background: #fbfcfe; }
.todo-card.running { border-color: var(--accent); box-shadow: 0 0 0 3px var(--soft); }
.todo-card.done .todo-title { color: var(--muted); text-decoration: line-through; }

.todo-main {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: start;
  gap: 10px;
}
.todo-check {
  width: 36px;
  height: 36px;
  min-height: 36px;
  border-radius: 50%;
  padding: 0;
}
.todo-card.done .todo-check {
  border-color: var(--done);
  background: #eaf8ef;
  color: var(--done);
}
.todo-title-wrap { min-width: 0; }
.todo-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 16px;
  font-weight: 900;
}
.todo-meta, .history-meta {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.todo-meta { margin-top: 4px; line-height: 1.5; }
.danger { color: var(--danger); min-height: 36px; padding: 0 10px; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.mini-tool {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbff;
  padding: 12px;
}
.mini-tool.active {
  border-color: var(--accent);
  background: var(--soft);
}
.mini-tool-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tool-badge {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.time-display {
  color: #0f2d69;
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 950;
  line-height: 1;
  white-space: nowrap;
}
.timer-duration {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.timer-duration label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}
.timer-duration input { width: 72px; }
.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.controls button { flex: 1 1 96px; min-height: 40px; padding: 0 10px; }

.empty {
  display: none;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  padding: 16px;
}
.empty.visible { display: block; }

.history-item { display: grid; gap: 4px; padding: 10px; }
.history-main {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 900;
}
.backup-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.backup-panel p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.backup-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.file-button { display: inline-grid; place-items: center; cursor: pointer; }
.file-button input { display: none; }

dialog {
  width: min(90vw, 360px);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  padding: 0;
}
dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
dialog form { display: grid; gap: 12px; padding: 18px; }
dialog p { color: var(--muted); line-height: 1.6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(92vw, 420px);
  transform: translate(-50%, 12px);
  border-radius: 12px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 640px) {
  .app-shell { padding-inline: 12px; }
  .tool-grid { grid-template-columns: 1fr; }
  .backup-panel { display: grid; }
  .backup-actions { justify-content: stretch; }
  .backup-actions button, .backup-actions .file-button { flex: 1; }
  .todo-main { grid-template-columns: 38px 1fr; }
  .todo-main .danger { grid-column: 2; justify-self: end; }
  .time-display { font-size: 24px; }
}
