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

:root {
  --bg:      #0d1117;
  --surface: #161b22;
  --surface2:#21262d;
  --border:  #30363d;
  --primary: #58a6ff;
  --accent:  #f78166;
  --success: #3fb950;
  --text:    #e6edf3;
  --muted:   #8b949e;
  --radius:  12px;
  --shadow:  0 8px 32px rgba(0,0,0,0.5);
}

html, body { height: 100%; }

body {
  font-family: 'Segoe UI','Hiragino Sans','Meiryo',sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ===== ツールバー ===== */
.toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 0 20px;
  z-index: 100;
}

.sound-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.sound-toggle input { accent-color: var(--primary); width: 16px; height: 16px; }

.toolbar-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.toolbar-btn:hover { background: var(--primary); color: #0d1117; border-color: var(--primary); }
.toolbar-btn.active { background: var(--primary); color: #0d1117; border-color: var(--primary); }

/* ===== アプリ本体 ===== */
.app {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  margin-top: 52px;
  display: flex;
  flex-direction: column;
}

/* 全画面モード */
body.fullscreen-mode {
  justify-content: center;
  padding: 0;
}

body.fullscreen-mode .toolbar { display: flex; }

body.fullscreen-mode .app {
  max-width: 100%;
  width: 100%;
  height: calc(100vh - 52px);
  margin-top: 52px;
  border-radius: 0;
  border: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

body.fullscreen-mode .tabs { width: 100%; max-width: 500px; }
body.fullscreen-mode .panel { width: 100%; max-width: 600px; }
body.fullscreen-mode .display { font-size: clamp(80px, 15vw, 180px); }
body.fullscreen-mode .controls-fixed { max-width: 500px; }
body.fullscreen-mode .controls-2 { max-width: 340px; }
body.fullscreen-mode .lap-list { max-height: 30vh; }
body.fullscreen-mode .presets { max-width: 500px; }
body.fullscreen-mode .timer-inputs { margin-bottom: 12px; }

/* ===== タブ ===== */
.tabs {
  display: flex;
  background: var(--surface2);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 28px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* ===== ディスプレイ ===== */
.display {
  font-size: 60px;
  font-weight: 300;
  text-align: center;
  letter-spacing: 3px;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  padding: 16px 0;
  text-shadow: 0 0 20px rgba(88,166,255,0.3);
  transition: font-size 0.3s;
}

/* ===== ボタン ===== */
.controls-fixed {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 8px 0 24px;
  width: 100%;
  flex-shrink: 0;
}

.controls-2 {
  grid-template-columns: repeat(2, 1fr);
}

.btn {
  padding: 12px 0;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #0d1117; }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

/* ===== プリセット ===== */
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
  width: 100%;
}

.preset-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.preset-btn:hover { background: var(--primary); color: #0d1117; border-color: var(--primary); }

/* ===== タイマー入力 ===== */
.timer-inputs {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}

.timer-inputs label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.timer-inputs input {
  width: 68px;
  padding: 10px 8px;
  text-align: center;
  font-size: 22px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  -moz-appearance: textfield;
}

.timer-inputs input::-webkit-inner-spin-button { display: none; }
.timer-inputs .sep { font-size: 24px; color: var(--muted); padding-bottom: 14px; }

/* ===== プログレスバー ===== */
.progress-bar-wrap {
  height: 4px;
  background: var(--surface2);
  border-radius: 4px;
  margin: 0 0 20px;
  overflow: hidden;
  width: 100%;
}

.progress-bar {
  height: 100%;
  width: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.5s linear, background 0.5s;
}

.progress-bar.warning { background: var(--accent); }

.timer-note {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
  margin-top: 8px;
}

/* ===== ボタンエリア固定 ===== */
.controls-fixed {
  position: sticky;
  top: 0;
}

/* ===== ラップ ===== */
.lap-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  width: 100%;
}

.lap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.lap-actions { display: flex; gap: 12px; }

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
}

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

.lap-list {
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.lap-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  animation: fadeIn 0.2s ease;
  border-radius: 4px;
}

.lap-list li.fastest { background: rgba(63,185,80,0.12); }
.lap-list li.slowest { background: rgba(247,129,102,0.12); }

.lap-no   { color: var(--muted); min-width: 55px; font-size: 13px; }
.lap-time { font-variant-numeric: tabular-nums; color: var(--primary); }
.lap-diff { font-size: 12px; color: var(--muted); text-align: right; min-width: 80px; }

.lap-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
  min-width: 32px;
  text-align: center;
}

.badge-fast { background: rgba(63,185,80,0.2); color: var(--success); }
.badge-slow { background: rgba(247,129,102,0.2); color: var(--accent); }

/* ===== ユーティリティ ===== */
.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== スマホ対応 ===== */
@media (max-width: 480px) {
  body { padding: 12px; padding-top: 64px; }
  .app { padding: 20px 14px; margin-top: 52px; }
  .display { font-size: 44px; letter-spacing: 1px; }
  .btn { font-size: 13px; }
  .timer-inputs input { width: 58px; font-size: 18px; }
}

/* ===== ミニウィジェット ===== */
.mini-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 18px;
  z-index: 999;
  cursor: grab;
  user-select: none;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  min-width: 160px;
  text-align: center;
  transition: box-shadow 0.2s;
}

.mini-widget:active { cursor: grabbing; box-shadow: 0 8px 32px rgba(0,0,0,0.7); }

.mini-time {
  font-size: 28px;
  font-weight: 300;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
}

.mini-label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}