:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #111827;
  --start: #16a34a;
  --end: #dc2626;
  --danger-bg: #fef2f2;
  --danger-text: #991b1b;
  --ok-bg: #f0fdf4;
  --ok-text: #166534;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c0f;
    --surface: #17181c;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #2a2b30;
    --primary: #f3f4f6;
    --danger-bg: #2a1414;
    --danger-text: #fca5a5;
    --ok-bg: #10251a;
    --ok-text: #86efac;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 16px 12px;
}

.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text);
  padding: 8px;
  cursor: pointer;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 20px 40px;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 12px;
}

input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

.btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-start {
  background: var(--start);
  color: white;
  padding: 22px;
  font-size: 1.2rem;
}

.btn-end {
  background: var(--end);
  color: white;
  padding: 22px;
  font-size: 1.2rem;
}

.btn-text {
  background: none;
  color: var(--muted);
  font-weight: 400;
}

.btn-inline {
  margin-top: 0;
  padding: 12px 16px;
  white-space: nowrap;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.preset-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}

.preset-chip:active {
  background: var(--border);
}

.preset-chips.is-disabled .preset-chip {
  opacity: 0.4;
  pointer-events: none;
}

.preset-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.preset-input-row input {
  flex: 1;
}

.preset-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
}

.preset-list-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-order-btns {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.preset-order-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}

.preset-order-btn:disabled {
  color: var(--border);
  cursor: not-allowed;
}

.preset-delete-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.empty-state {
  margin-top: 40px;
  text-align: center;
  color: var(--muted);
}

#active-form {
  text-align: center;
}

.active-label {
  color: var(--muted);
  margin: 24px 0 4px;
}

.active-label.is-hidden {
  visibility: hidden;
}

.active-work-name {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 4px 0;
}

.elapsed {
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  margin: 12px 0 24px;
  color: var(--muted);
}

.banner {
  padding: 12px 14px;
  border-radius: 10px;
  margin-top: 12px;
  font-size: 0.9rem;
}

.banner-error {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.banner-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.ds-name {
  font-size: 0.9rem;
  color: var(--muted);
}

#history-section {
  margin-top: 36px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.history-heading {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 10px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
}

.history-item .history-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item .history-time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 0.85rem;
}

.history-empty {
  color: var(--muted);
  font-size: 0.85rem;
}
