: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);
}

.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;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.history-header .section-title { margin: 0; }

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

.tz-picker select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 0.78rem;
  max-width: 220px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
  cursor: pointer;
}

.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);
}

.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 {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  font-size: 0.9rem;
}

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