:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-card: #1b1f28;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-dim: #8a90a0;
  --accent: #6c8cff;
  --accent-dim: #3a4a8c;
  --danger: #ff6b6b;
  --success: #4dd08a;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.hidden { display: none !important; }

.title {
  font-size: 1.4rem;
  font-weight: 600;
  text-align: center;
  margin: 48px 0 4px;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 32px;
}

.char-cards {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.char-card {
  flex: 1;
  max-width: 160px;
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.char-card:hover {
  border-color: var(--accent);
}

.char-card:active {
  transform: scale(0.97);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.welcome {
  font-size: 1.1rem;
  font-weight: 500;
  margin: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}

.link-btn:hover { color: var(--text); }

.timer-card, .scoreboard-card, .stats-card, .history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.timer-status {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.timer-live {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 16px;
  color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 12px;
}

.btn {
  flex: 1;
  padding: 16px;
  border-radius: 12px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active:not(:disabled) { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-start {
  background: var(--success);
  color: #06231a;
}

.btn-stop {
  background: var(--danger);
  color: #2b0a0a;
}

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.notify-toggle-row {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.notify-recipient-field {
  margin-bottom: 0;
}

.notify-recipient-field select {
  width: 100%;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 0 0 16px;
}

.scoreboard {
  display: flex;
  gap: 16px;
}

.score-col {
  flex: 1;
  text-align: center;
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 16px 8px;
}

.score-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.score-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 12px;
}

.stat-item .stat-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-item .stat-value {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 4px 10px;
  margin-right: 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transform: translateY(1px);
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--text);
}

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

.history-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.tz-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 0;
}

.tz-picker select {
  max-width: 220px;
}

/* ---- Custom select styling ---- */
select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238a90a0' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 28px 8px 10px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

select:hover {
  border-color: #3a4152;
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 140, 255, 0.18);
}

select option {
  background: var(--bg-elevated);
  color: var(--text);
}

/* ---- Custom checkbox styling ---- */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
}

.toggle input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin: 0;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.toggle input[type="checkbox"]:hover {
  border-color: #3a4152;
}

.toggle input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input[type="checkbox"]::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #0c1020;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.12s ease;
}

.toggle input[type="checkbox"]:checked::after {
  transform: rotate(45deg) scale(1);
}

.toggle input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(108, 140, 255, 0.25);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.history-item {
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.85rem;
}

.history-item.deleted {
  opacity: 0.45;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-duration {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-meta {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.history-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 4px 6px;
  border-radius: 6px;
}

.icon-btn:hover {
  background: var(--bg-card);
  color: var(--text);
}

.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.notif-status {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.notif-status.success {
  color: var(--success);
  background: rgba(77, 208, 138, 0.12);
}

.notif-status.failed {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.12);
}

.notif-content {
  margin-top: 4px;
}

.notif-error {
  color: var(--danger);
  font-size: 0.72rem;
  margin-top: 4px;
}

.edit-log {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
}

.modal-card h3 {
  margin: 0 0 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.field input, .field select, .field textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
}

.field-hint {
  align-self: flex-end;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
