:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-soft: #f0f0f2;
  --stroke: rgba(0, 0, 0, 0.08);
  --text: #1c1c1f;
  --text-muted: rgba(28, 28, 31, 0.6);
  --accent: #3563ff;
  --accent-soft: rgba(53, 99, 255, 0.12);
  --shadow: 0 12px 32px rgba(23, 25, 35, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font: "SF Pro Display", "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  color-scheme: inherit;
}

:root[data-theme="dark"],
.app[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111118;
  --surface: #1b1c24;
  --surface-soft: #242632;
  --stroke: rgba(255, 255, 255, 0.08);
  --text: #f6f6f8;
  --text-muted: rgba(246, 246, 248, 0.6);
  --accent: #7a8bff;
  --accent-soft: rgba(122, 139, 255, 0.18);
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}

:root[data-theme="system"],
.app[data-theme="system"] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"],
  .app[data-theme="system"] {
    color-scheme: dark;
    --bg: #111118;
    --surface: #1b1c24;
    --surface-soft: #242632;
    --stroke: rgba(255, 255, 255, 0.08);
    --text: #f6f6f8;
    --text-muted: rgba(246, 246, 248, 0.6);
    --accent: #7a8bff;
    --accent-soft: rgba(122, 139, 255, 0.18);
    --shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  }
}
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

.app {
  width: min(720px, 100%);
  min-height: 100vh;
  padding: 24px clamp(16px, 4vw, 32px) 72px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
  margin: 0 auto;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  font-size: 20px;
  font-weight: 600;
}

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

.icon-btn {
  appearance: none;
  border: none;
  background: var(--surface);
  color: var(--text);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition);
}

.icon-btn:hover {
  transform: translateY(-2px);
}

.main {
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex: 1;
}

.timer-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
}

.timer-display {
  font-size: clamp(48px, 12vw, 80px);
  font-weight: 600;
  letter-spacing: 4px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 10vw, 40px);
}

.circle-btn {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--surface);
  color: var(--text);
  width: clamp(92px, 28vw, 128px);
  height: clamp(92px, 28vw, 128px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(24px, 6vw, 32px);
  font-weight: 500;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), border var(--transition);
  box-shadow: var(--shadow);
}

.lap-btn {
  font-size: clamp(30px, 8vw, 40px);
}

.circle-btn.primary {
  background: var(--accent);
  color: #fff;
  border: none;
}

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

.circle-btn:not(.primary):not(:disabled):hover,
.ghost-btn:hover {
  background: var(--surface-soft);
  transform: translateY(-1px);
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), border var(--transition);
}

.circle-btn.primary:not(:disabled):hover {
  background: #2748d9;
  transform: translateY(-1px);
}

.lap-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h2,
.history-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.lap-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lap-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.lap-info {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.lap-label {
  font-weight: 600;
  font-size: 15px;
}

.lap-total {
  display: inline-flex;
  font-family: "JetBrains Mono", "SFMono-Semibold", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 16px;
  white-space: nowrap;
  align-items: center;
}

.lap-split {
  display: inline-flex;
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  align-items: center;
}

.lap-note-text {
  flex: 1 1 180px;
  font-size: 14px;
  color: var(--text);
  min-height: 20px;
  line-height: 1.3;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.lap-note-input {
  flex: 1 1 200px;
  margin-left: auto;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 14px;
  background: var(--surface-soft);
  color: var(--text);
  resize: none;
  height: 32px;
  line-height: 1.3;
}

.lap-note-input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.lap-note-edit {
  appearance: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: var(--surface);
  color: var(--text);
  width: 34px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--transition), border var(--transition), transform var(--transition);
}

.lap-note-edit:hover {
  background: var(--surface-soft);
  transform: translateY(-1px);
}

.lap-note-edit {
  margin-left: auto;
}

@media (max-width: 560px) {
  .lap-card {
    padding: 10px 14px;
    gap: 10px;
  }

  .controls {
    gap: clamp(12px, 6vw, 20px);
  }

  .circle-btn {
    width: clamp(66px, 20vw, 84px);
    height: clamp(66px, 20vw, 84px);
    font-size: clamp(18px, 5.5vw, 26px);
    box-shadow: 0 8px 20px rgba(23, 25, 35, 0.1);
  }

  .lap-btn {
    font-size: clamp(22px, 6.5vw, 30px);
  }

  .lap-info {
    gap: 10px;
  }

  .lap-split {
    font-size: 13px;
  }

  .lap-total {
    font-size: 15px;
  }

  .lap-note-text,
  .lap-note-input {
    font-size: 13px;
    flex: 1 1 150px;
  }

  .lap-note-edit {
    margin-left: auto;
  }
}

.history-panel {
  background: rgba(0, 0, 0, 0.02);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app[data-theme="light"] .history-panel,
.app[data-theme="dark"] .history-panel,
.app[data-theme="system"] .history-panel {
  background: rgba(255, 255, 255, 0.03);
}

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

.date-picker-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.date-nav {
  appearance: none;
  border: none;
  background: var(--surface);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.date-nav:hover {
  background: var(--surface-soft);
  transform: translateY(-1px);
}

.date-picker-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 8px 20px 6px 14px;
  border: 1px solid transparent;
  transition: background var(--transition), box-shadow var(--transition), border var(--transition);
}

.date-picker-wrapper:hover {
  background: var(--surface-soft);
}

.date-picker-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.date-picker {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 4px 0;
}

.date-picker:focus {
  outline: none;
}

.date-picker::-webkit-calendar-picker-indicator {
  opacity: 0;
  cursor: pointer;
}

.date-picker-trigger {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  width: 22px;
  height: 22px;
  margin-right: 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.date-picker-trigger::before {
  content: "";
  width: 17px;
  height: 17px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%23000' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='5.5' width='13' height='11' rx='2'/%3E%3Cpath d='M3.5 8.5h13M7 3.5v4M13 3.5v4'/%3E%3C/svg%3E") center / contain no-repeat;
}

.date-picker-trigger:hover {
  background: var(--surface);
  transform: translateY(-50%) translateY(-1px);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
}



.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.history-time {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  flex-wrap: wrap;
}

.history-total-inline {
  font-family: "JetBrains Mono", "SFMono-Semibold", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-action {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), transform var(--transition);
}

.history-action:hover {
  background: var(--surface-soft);
  transform: translateY(-1px);
}

.history-total {
  color: var(--text-muted);
}

.history-lap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-lap-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.history-lap-note-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.history-note-text {
  color: var(--text);
  font-size: 13px;
  word-break: break-word;
}

.history-note-input {
  width: clamp(140px, 50vw, 260px);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  background: var(--surface-soft);
  color: var(--text);
  resize: none;
  overflow: hidden;
  min-height: 48px;
  line-height: 1.4;
}

.history-note-input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.settings-drawer {
  position: fixed;
  inset: 0;
  background: rgba(15, 16, 24, 0.32);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 20;
  overflow: auto;
}

.settings-content {
  width: min(360px, 92vw);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
  animation: settings-pop 0.24s ease both;
}

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

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--stroke);
  border-radius: 24px;
  transition: background var(--transition);
}

.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
  box-shadow: var(--shadow);
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
  background: #fff;
}

.settings-drawer[hidden] {
  display: none;
}

@keyframes settings-pop {
  0% {
    transform: translateY(-12px) scale(0.96);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (max-width: 600px) {
  .app {
    padding-bottom: 96px;
  }

  .history-panel {
    margin: 0 -8px;
    border-radius: 20px 20px 0 0;
    padding-bottom: 32px;
  }
}
