/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --font: 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;

  /* Dark theme (default) */
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --border: #334;
  --text: #e0e0e8;
  --text-muted: #888;
  --accent: #e94560;
  --accent-hover: #c73350;

  --ring-idle: #444;
  --ring-running: #4caf50;
  --ring-paused: #ff9800;
  --ring-done: #e94560;

  --btn-primary-bg: #4caf50;
  --btn-primary-text: #fff;
  --btn-warning-bg: #ff9800;
  --btn-warning-text: #fff;
  --btn-secondary-bg: #334;
  --btn-secondary-text: #ccc;
  --btn-ghost-bg: transparent;
  --btn-ghost-text: #aaa;
  --btn-ghost-border: #444;

  --card-bg: #16213e;
  --card-border: #334;
  --card-done-bg: rgba(233, 69, 96, 0.08);
  --card-done-border: #e94560;

  --modal-bg: #1a1a2e;
  --modal-border: #334;
  --input-bg: #0f3460;
  --input-border: #446;
  --input-text: #e0e0e8;

  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg: #f0f4f8;
  --surface: #fff;
  --surface2: #e8eef5;
  --border: #dde;
  --text: #222;
  --text-muted: #666;
  --accent: #d63031;
  --accent-hover: #b72626;

  --ring-idle: #ccc;
  --ring-running: #27ae60;
  --ring-paused: #e67e22;
  --ring-done: #d63031;

  --btn-primary-bg: #27ae60;
  --btn-primary-text: #fff;
  --btn-warning-bg: #e67e22;
  --btn-warning-text: #fff;
  --btn-secondary-bg: #dde;
  --btn-secondary-text: #444;
  --btn-ghost-bg: transparent;
  --btn-ghost-text: #555;
  --btn-ghost-border: #bbb;

  --card-bg: #fff;
  --card-border: #dde;
  --card-done-bg: rgba(214, 48, 49, 0.05);
  --card-done-border: #d63031;

  --modal-bg: #fff;
  --modal-border: #dde;
  --input-bg: #f5f5f5;
  --input-border: #ccc;
  --input-text: #222;

  --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

/* ─── Top Bar ────────────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
  flex-wrap: wrap;
}

.app-title {
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
}

.top-controls {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn:hover { filter: brightness(1.1); }
.btn:active { filter: brightness(0.9); }

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

.btn-ghost {
  background: var(--btn-ghost-bg);
  color: var(--btn-ghost-text);
  border: 1px solid var(--btn-ghost-border);
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}

.btn-ghost.active { color: var(--text); border-color: var(--accent); }

.btn-add {
  background: var(--accent);
  color: #fff;
  padding: 0.7rem 1.8rem;
  font-size: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.btn-preset {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
}

/* ─── Container ──────────────────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ─── Timer Grid ─────────────────────────────────────────────────────────────── */
.timer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.2rem;
  margin-bottom: 1.5rem;
}

.no-timers {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 1rem;
}

/* ─── Timer Card ─────────────────────────────────────────────────────────────── */
.timer-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1.2rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, background 0.2s;
}

.timer-card.status-completed {
  background: var(--card-done-bg);
  border-color: var(--card-done-border);
}

.timer-card.status-running {
  border-color: var(--ring-running);
}

.timer-card.status-paused {
  border-color: var(--ring-paused);
}

.btn-delete {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.2rem 0.3rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s;
}

.btn-delete:hover { color: var(--accent); }

/* ─── Progress Ring ──────────────────────────────────────────────────────────── */
.ring-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

.progress-ring {
  width: 120px;
  height: 120px;
}

.ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.ring-fg {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dasharray 0.3s ease;
}

.ring-time {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

/* ─── Pulse animation for completed timers ───────────────────────────────────── */
@keyframes ring-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ring-pulse .ring-fg {
  animation: ring-pulse 0.8s ease-in-out infinite;
}

/* ─── Card misc ──────────────────────────────────────────────────────────────── */
.timer-label {
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
}

.done-badge {
  background: var(--ring-done);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  letter-spacing: 0.03em;
}

.timer-controls {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ─── Add row ────────────────────────────────────────────────────────────────── */
.add-row {
  display: flex;
  justify-content: center;
  padding-top: 0.5rem;
}

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: 12px;
  padding: 1.8rem 1.6rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label, label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.input {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 6px;
  color: var(--input-text);
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 0.5rem 0.7rem;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus { border-color: var(--accent); }

.time-inputs {
  display: flex;
  gap: 0.5rem;
}

.time-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex: 1;
}

.input-num {
  width: 100%;
  text-align: center;
  font-size: 1.1rem;
  padding: 0.4rem 0.2rem;
}

/* remove number input spinners for cleaner look */
.input-num::-webkit-inner-spin-button,
.input-num::-webkit-outer-spin-button { opacity: 0.5; }

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .top-bar { padding: 0.6rem 0.8rem; }
  .app-title { font-size: 1rem; }
  .btn-ghost { font-size: 0.72rem; padding: 0.3rem 0.5rem; }
  .timer-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.8rem; }
  .ring-wrap { width: 100px; height: 100px; }
  .progress-ring { width: 100px; height: 100px; }
  .ring-time { font-size: 0.95rem; }
}
