:root {
  --background: #0a0a0f;
  --surface: #1a1a2e;
  --surface-raised: #202038;
  --border: #2a2a3e;
  --text: #e0e0e0;
  --muted: #888;
  --accent: #00f5d4;
  --rest: #7bed9f;
  --xp: #f9ca24;
  --error: #ff6b6b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--text);
  background: var(--background);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: 100%;
  max-width: 1280px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--background);
}

.titlebar {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
}

.window-controls {
  display: flex;
  gap: 8px;
  width: 110px;
}

.traffic {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  -webkit-app-region: no-drag;
}

.traffic-close {
  background: #ff5f57;
}

.traffic-minimize {
  background: #febc2e;
}

.traffic-disabled {
  background: #28c840;
  opacity: 0.45;
}

.icon-button {
  color: var(--muted);
  background: transparent;
  font-size: 16px;
  -webkit-app-region: no-drag;
}

.columns {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr) minmax(210px, 0.55fr);
  min-height: calc(100vh - 42px);
}

.timer-column,
.tasks-column,
.stats-column {
  min-width: 0;
  min-height: 0;
  padding: 22px;
}

.timer-column,
.tasks-column {
  border-right: 1px solid var(--border);
}

.timer-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.timer-ring {
  position: relative;
  width: 220px;
  height: 220px;
}

.timer-ring svg {
  width: 220px;
  height: 220px;
}

.ring-bg,
.ring-progress {
  fill: none;
  stroke-width: 12;
}

.ring-bg {
  stroke: var(--border);
}

.ring-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 603.19;
  stroke-dashoffset: 0;
  transform: rotate(-90deg);
  transform-origin: 110px 110px;
  transition: stroke-dashoffset 0.35s ease, stroke 0.2s ease;
}

.timer-time {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 48px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.mode-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 700;
}

.mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.timer-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 34px;
  padding: 8px 15px;
  border-radius: 8px;
  font-weight: 700;
}

.primary-button {
  color: #07110f;
  background: var(--accent);
}

.secondary-button {
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
}

.primary-button:disabled {
  cursor: default;
  opacity: 0.45;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 20px;
}

.session-list {
  height: 386px;
  margin: 18px 0;
  overflow: auto;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.session-card {
  padding: 12px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s ease;
}

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

.session-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
}

.session-xp {
  color: var(--xp);
  font-weight: 800;
}

.stats-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.level-number {
  font-size: 20px;
  font-weight: 800;
}

.level-name,
.xp-progress p {
  color: var(--muted);
}

.bar {
  height: 8px;
  overflow: hidden;
  background: var(--border);
  border-radius: 8px;
}

.bar-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--rest));
  transition: width 0.25s ease;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.52);
}

.modal {
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  animation: modal-in 0.18s ease;
}

.modal-wide {
  width: 450px;
}

input {
  width: 100%;
  color: var(--text);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: 0;
  padding: 11px 12px;
}

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

.xp-float {
  color: var(--xp);
  font-size: 18px;
  font-weight: 800;
  animation: xp-rise 1.5s ease infinite;
}

.segmented {
  display: flex;
  gap: 8px;
}

.segmented button.is-active {
  color: #07110f;
  background: var(--accent);
  border-color: var(--accent);
}

.toast {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 50;
  padding: 10px 14px;
  background: var(--surface-raised);
  border: 1px solid rgba(0, 245, 212, 0.45);
  border-radius: 8px;
  font-weight: 700;
  animation: toast-in 0.22s ease;
}

.level-up {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.20);
}

.level-up canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#levelUpText {
  position: relative;
  padding: 24px;
  color: var(--accent);
  background: rgba(26, 26, 46, 0.92);
  border-radius: 8px;
  font-size: 32px;
  font-weight: 900;
  box-shadow: 0 0 42px rgba(0, 245, 212, 0.36);
}

.hidden {
  display: none !important;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes xp-rise {
  from {
    opacity: 0.4;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Tasks column */
.tasks-column { display: flex; flex-direction: column; padding: 18px; gap: 12px; overflow: hidden; }
.tasks-week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.tasks-day-button { min-width: 0; height: 48px; padding: 5px 4px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-items: center; gap: 0 4px; color: #8a8a95; background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.07); border-radius: 6px; }
.tasks-day-button:hover { color: #fff; background: rgba(255,255,255,0.05); }
.tasks-day-button.is-selected { color: #fff; border-color: rgba(0,245,212,0.55); background: rgba(0,245,212,0.08); }
.tasks-day-button.is-today .tasks-day-name { color: var(--accent); }
.tasks-day-name { grid-column: 1 / 2; font-size: 11px; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tasks-day-date { grid-column: 1 / 2; font-size: 14px; color: #e5e5ea; }
.tasks-day-count { grid-column: 2 / 3; grid-row: 1 / 3; min-width: 18px; height: 18px; padding: 0 4px; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: rgba(255,255,255,0.06); color: #c9c9d1; font-size: 11px; }
.tasks-day-button.is-selected .tasks-day-count { background: rgba(0,245,212,0.18); color: #fff; }
.tasks-rollover { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid rgba(255,204,102,0.22); border-radius: 6px; background: rgba(255,204,102,0.07); color: #f0dca8; font-size: 12px; }
.tasks-rollover-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tasks-rollover .secondary-button { min-height: 26px; padding: 5px 9px; font-size: 12px; }
.tasks-overdue-panel { max-height: 160px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid rgba(255,255,255,0.08); border-radius: 6px; background: rgba(255,255,255,0.035); }
.tasks-overdue-group { display: flex; flex-direction: column; gap: 4px; }
.tasks-overdue-date { color: #f0dca8; font-size: 12px; font-weight: 600; }
.tasks-overdue-item { color: #c9c9d1; font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; padding-left: 8px; border-left: 1px solid rgba(255,255,255,0.08); }
.tasks-tabs { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid rgba(255,255,255,0.08); padding-bottom: 2px; }
.tasks-tab { background: none; border: none; color: #8a8a95; padding: 8px 12px; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tasks-tab.is-active { color: #fff; border-bottom-color: var(--accent); }
.tasks-copy-button { width: 28px; height: 28px; margin-left: auto; margin-bottom: 2px; padding: 0; color: #8a8a95; background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); border-radius: 6px; font-size: 14px; line-height: 1; }
.tasks-copy-button:hover:not(:disabled) { color: #fff; border-color: rgba(0,245,212,0.45); background: rgba(0,245,212,0.08); }
.tasks-copy-button:disabled { cursor: default; opacity: 0.35; }
.tasks-view { flex: 1; display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
.tasks-bulk-panel { display: flex; flex-direction: column; gap: 8px; }
.tasks-bulk-toggle { align-self: flex-start; min-height: 28px; padding: 6px 10px; font-size: 12px; }
.tasks-bulk-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }
.tasks-bulk-form textarea { min-height: 72px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 6px; padding: 9px 10px; color: #fff; font-family: inherit; font-size: 13px; resize: vertical; outline: 0; }
.tasks-bulk-form textarea:focus { border-color: var(--accent); }
.tasks-bulk-form .primary-button { align-self: end; min-height: 34px; padding: 8px 12px; }
.tasks-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.tasks-empty { display: flex; flex-direction: column; gap: 6px; padding: 18px 0; text-align: center; }
.tasks-empty h1 { margin: 0; font-size: 15px; }
.tasks-empty .subtitle { color: #8a8a95; font-size: 12px; margin: 0; }
.tasks-inline-row { padding-top: 4px; }
.tasks-inline-row input { width: 100%; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 6px; padding: 8px 10px; color: #fff; font-family: inherit; font-size: 13px; }

/* Task rows */
.task-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: rgba(255,255,255,0.03); border-radius: 6px; cursor: grab; user-select: none; transition: opacity 200ms; }
.task-row[draggable="true"]:active { cursor: grabbing; }
.task-row.is-dragging { opacity: 0.4; }
.task-row.is-drop-target { box-shadow: inset 0 2px 0 var(--accent); }
.task-row.is-leaving { opacity: 0; transform: translateX(8px); transition: opacity 200ms, transform 200ms; }
.task-row .checkbox { width: 16px; height: 16px; border: 1px solid #666; border-radius: 3px; flex-shrink: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 11px; }
.task-row.is-done .checkbox { background: var(--accent); border-color: var(--accent); color: #fff; }
.task-row .title { flex: 1; font-size: 13px; color: #e5e5ea; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.task-row.is-done .title { text-decoration: line-through; color: #8a8a95; }
.task-row .grip { color: #4a4a52; font-size: 12px; letter-spacing: -1px; }
.task-row .task-action { padding: 0; width: 22px; height: 22px; min-height: 0; display: flex; align-items: center; justify-content: center; background: transparent; border: 0; border-radius: 4px; color: #6a6a75; font-size: 12px; opacity: 0; transition: opacity 120ms ease, color 120ms ease, background 120ms ease; flex-shrink: 0; }
.task-row:hover .task-action,
.task-row.is-editing .task-action { opacity: 1; }
.task-row .task-action:hover { background: rgba(255,255,255,0.06); color: #e5e5ea; }
.task-row .task-action-delete:hover { color: var(--error); }
.task-row .title-input { flex: 1; min-width: 0; padding: 4px 6px; font-size: 13px; line-height: 1.2; background: rgba(255,255,255,0.06); border: 1px solid rgba(0,245,212,0.55); border-radius: 4px; color: #fff; outline: 0; }
.task-row.is-editing { cursor: default; background: rgba(255,255,255,0.05); }

/* History overlay */
.history-overlay { position: absolute; inset: 0; background: var(--background); display: flex; flex-direction: column; z-index: 30; }
.history-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.history-header h2 { margin: 0; font-size: 16px; }
.history-body { flex: 1; overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 16px; }
.history-today { background: rgba(255,255,255,0.04); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.history-today h3 { margin: 0; font-size: 15px; }
.history-meta { color: #8a8a95; font-size: 12px; }
.history-closed-list { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #d0d0d5; }
.history-chart { display: flex; align-items: flex-end; gap: 4px; height: 72px; padding: 8px; background: rgba(255,255,255,0.03); border-radius: 8px; }
.history-chart-bar { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: 0.85; }
.history-chart-bar.is-empty { background: rgba(255,255,255,0.06); }
.history-feed { display: flex; flex-direction: column; gap: 2px; }
.history-row { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.history-row:hover { background: rgba(255,255,255,0.04); }
.history-row.is-expanded { background: rgba(255,255,255,0.04); flex-direction: column; align-items: stretch; gap: 6px; cursor: default; }
.history-row .history-row-head { display: flex; justify-content: space-between; }

@media (max-width: 1024px) {
  .columns {
    grid-template-columns: minmax(260px, 0.85fr) minmax(340px, 1.15fr);
  }

  .timer-column,
  .tasks-column,
  .stats-column {
    padding: 18px;
  }

  .tasks-column {
    border-right: 0;
  }

  .stats-column {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(150px, 0.7fr) minmax(220px, 1fr) repeat(3, minmax(100px, auto)) auto;
    align-items: center;
    gap: 12px;
    border-top: 1px solid var(--border);
  }

  .stats-column .level-block,
  .stats-column .xp-progress {
    min-width: 0;
  }

  .stats-column p {
    white-space: nowrap;
  }
}

@media (max-width: 760px) {
  .titlebar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--background);
  }

  .columns {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .timer-column,
  .tasks-column,
  .stats-column {
    width: 100%;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .timer-column {
    min-height: auto;
    gap: 14px;
    justify-content: flex-start;
  }

  .timer-ring,
  .timer-ring svg {
    width: 180px;
    height: 180px;
  }

  .timer-time {
    font-size: 38px;
  }

  .timer-actions,
  .modal-actions {
    width: 100%;
  }

  .timer-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .timer-actions .primary-button,
  .timer-actions .secondary-button,
  .modal-actions .primary-button,
  .modal-actions .secondary-button {
    min-width: 0;
    width: 100%;
    flex: 1;
  }

  .tasks-column {
    min-height: 520px;
  }

  .tasks-week-strip {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .tasks-day-button {
    position: relative;
    grid-template-columns: minmax(0, 1fr);
    height: 44px;
    padding: 5px 2px;
  }

  .tasks-day-name {
    font-size: 10px;
  }

  .tasks-day-count {
    position: absolute;
    top: 4px;
    right: 3px;
    min-width: 14px;
    height: 14px;
    padding: 0;
    font-size: 9px;
  }

  .tasks-rollover {
    align-items: stretch;
    flex-direction: column;
  }

  .tasks-rollover-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .tasks-tabs {
    gap: 2px;
  }

  .tasks-tab {
    padding: 8px 7px;
    font-size: 12px;
  }

  .tasks-copy-button {
    width: 32px;
    height: 32px;
  }

  .tasks-bulk-form {
    grid-template-columns: 1fr;
  }

  .tasks-bulk-form .primary-button {
    width: 100%;
  }

  .tasks-empty {
    align-items: center;
  }

  .tasks-empty .subtitle {
    max-width: 300px;
    line-height: 1.35;
  }

  .task-row {
    min-height: 40px;
  }

  .task-row .task-action {
    width: 28px;
    height: 28px;
    opacity: 1;
  }

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

  .stats-column .level-block,
  .stats-column .xp-progress {
    grid-column: 1 / -1;
  }

  .stats-column .secondary-button {
    grid-column: 1 / -1;
  }

  .modal {
    width: min(360px, calc(100vw - 32px));
    padding: 20px;
  }

  .modal-wide {
    width: min(450px, calc(100vw - 32px));
  }

  .toast {
    left: 16px;
    right: 16px;
    text-align: center;
  }

  .history-overlay {
    position: fixed;
  }

  .history-header,
  .history-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .history-row .history-row-head {
    flex-direction: column;
    gap: 4px;
  }
}

@media (max-width: 420px) {
  .titlebar {
    padding: 0 12px;
  }

  .timer-column,
  .tasks-column,
  .stats-column {
    padding: 14px 12px;
  }

  .timer-ring,
  .timer-ring svg {
    width: 156px;
    height: 156px;
  }

  .timer-time {
    font-size: 32px;
  }

  .tasks-column {
    min-height: 500px;
  }

  .tasks-week-strip {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .tasks-day-count {
    min-width: 16px;
    height: 16px;
    font-size: 10px;
  }

  .tasks-tab {
    padding: 8px 5px;
  }

  .stats-column {
    grid-template-columns: 1fr;
  }

  #levelUpText {
    max-width: calc(100vw - 32px);
    font-size: 24px;
    text-align: center;
  }
}
