:root {
  --bg-paused: #3a3a3c;
  --bg-working: #2f5d3a;
  --bg-procrastinating: #6b3a3a;
  --fg: #f1f1f1;
  --fg-dim: rgba(241, 241, 241, 0.55);
  --fg-faint: rgba(241, 241, 241, 0.3);
  --accent: rgba(255, 255, 255, 0.12);
  --accent-strong: rgba(255, 255, 255, 0.22);
  --danger: #c45a5a;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --bg: var(--bg-paused);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 600ms ease;
}

body[data-state="working"]        { --bg: var(--bg-working); }
body[data-state="procrastinating"] { --bg: var(--bg-procrastinating); }
body[data-state="paused"]         { --bg: var(--bg-paused); }

#viewport {
  position: relative;
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  cursor: pointer;
  user-select: none;
  container-type: size;
  container-name: vp;
}

body[data-state="paused"] #viewport { cursor: default; }

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.spacer { flex: 1; }

.state-indicator {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
  font-weight: 600;
}

.icon-btn {
  background: var(--accent);
  border: none;
  color: var(--fg);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1;
  padding: 0;
}
.icon-btn:hover { background: var(--accent-strong); }
.icon-btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.clocks {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 8px;
  min-height: 0;
}

.clock {
  text-align: center;
  line-height: 1;
  transition: opacity 250ms ease, transform 250ms ease;
}
.clock .label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-faint);
  margin-bottom: 2px;
}
.clock .time {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: clamp(18px, 12cqi, 56px);
  letter-spacing: 0.02em;
}

/* Active/inactive emphasis */
body[data-state="working"] .clock.proc,
body[data-state="procrastinating"] .clock.work,
body[data-state="paused"] .clock {
  opacity: 0.45;
}
body[data-state="working"] .clock.proc .time,
body[data-state="procrastinating"] .clock.work .time {
  font-size: clamp(12px, 5cqi, 22px);
  color: var(--fg-dim);
}
body[data-state="paused"] .clock .time {
  font-size: clamp(14px, 7cqi, 32px);
  color: var(--fg-dim);
}

.progress {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0 4px 2px;
}
.progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: rgba(255,255,255,0.7);
  transition: width 600ms ease;
}
.progress-text {
  font-size: 10px;
  color: var(--fg-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.task-chips-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 36px;
  display: flex;
  justify-content: center;
  pointer-events: none;
  padding: 0 8px;
  container-type: inline-size;
}
.task-chips {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  max-width: 100%;
}
.task-chip {
  background: rgba(0,0,0,0.18);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--fg-dim);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
  line-height: 1;
}
.task-chip:hover { background: rgba(0,0,0,0.28); color: var(--fg); }
.task-chip.active {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.45);
  color: var(--fg);
}

.pip-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.pip-placeholder button {
  background: rgba(0,0,0,0.2);
  border: 1px dashed rgba(255,255,255,0.25);
  color: var(--fg-dim);
  padding: 10px 14px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 12px;
  cursor: pointer;
}
.pip-placeholder button:hover { color: var(--fg); border-color: rgba(255,255,255,0.45); }

.reason-picker {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 95%;
  z-index: 5;
  animation: rise 220ms ease;
}
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.reason-picker-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.reason-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.reason-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.reason-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  color: var(--fg);
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
}
.reason-btn:hover { background: rgba(255,255,255,0.22); }
.reason-dismiss {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 12px;
  width: 18px;
  height: 18px;
  padding: 0;
}

.toast {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.55);
  color: var(--fg);
  padding: 5px 10px;
  font-size: 11px;
  border-radius: 6px;
  z-index: 20;
  animation: rise 200ms ease;
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: stretch; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal-panel {
  position: relative;
  background: #232325;
  color: var(--fg);
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(255,255,255,0.08);
  margin-left: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: sticky;
  top: 0;
  background: #232325;
}
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-body section { display: flex; flex-direction: column; gap: 6px; }
.modal-body h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-dim); font-weight: 600; }
.modal-body p.hint { margin: 0; font-size: 11px; color: var(--fg-faint); }
.credit { margin: 8px 0 0; text-align: center; font-size: 11px; color: var(--fg-faint); }
.credit a { color: var(--fg-dim); text-decoration: none; }
.credit a:hover { color: var(--fg); text-decoration: underline; }

.row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.row.wrap { flex-wrap: wrap; }
.row input[type="number"] { width: 60px; }
.row input[type="text"] { flex: 1; }

input[type="number"], input[type="text"] {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--fg);
  font-family: var(--font);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
}
input[type="number"]:focus, input[type="text"]:focus { outline: none; border-color: rgba(255,255,255,0.4); }

.btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--fg);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
}
.btn:hover { background: rgba(255,255,255,0.2); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #d36868; }

.muted { color: var(--fg-dim); }

.chip-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.1);
  padding: 3px 4px 3px 8px;
  border-radius: 999px;
  font-size: 11px;
}
.chip button {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0 4px;
}
.chip button:hover { color: var(--fg); }

.summary { font-size: 13px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.summary .pair { display: flex; gap: 8px; }
.summary .key { color: var(--fg-dim); min-width: 90px; }

.modal-body h4 {
  margin: 4px 0 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  font-weight: 600;
}
.sub-block { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.kv-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.kv-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
}
.kv-list .k { color: var(--fg); }
.kv-list .v { color: var(--fg-dim); }
.kv-list .empty { color: var(--fg-faint); font-style: italic; }

.history-list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; font-size: 12px; }
.history-list li {
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-variant-numeric: tabular-nums;
}
.history-list .h-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 0;
  cursor: pointer;
}
.history-list .h-row:hover { background: rgba(255,255,255,0.04); }
.history-list .h-date { color: var(--fg-dim); }
.history-list .h-detail {
  padding: 4px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-list .h-empty { color: var(--fg-faint); border: none; padding: 4px 0; }

/* Container query responsive design */
@container vp (max-width: 280px) {
  .progress-text { display: none; }
  .progress-bar { height: 3px; }
  .bar { padding: 4px 6px; }
  .icon-btn { width: 24px; height: 24px; }
  .state-indicator { font-size: 10px; }
  .clock .label { font-size: 9px; }
}

@container vp (max-width: 240px) {
  #progress-wrap { display: none; }
  .task-chips-wrap { bottom: 8px; }
  .reason-picker { bottom: 8px; }
  #settings-btn, #stats-btn, #popout-btn { display: none; }
  .clock .label { display: none; }
  .clocks { gap: 2px; }
}

@container vp (max-height: 200px) {
  .clocks { padding: 2px 6px; }
  .clock .label { display: none; }
}

@container vp (max-width: 220px) and (max-height: 170px) {
  .bar.bottom { display: none; }
  .task-chips-wrap { display: none; }
  .reason-picker { font-size: 10px; bottom: 4px; }
  .state-indicator { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html, body, .progress-fill, .clock { transition: none; }
  .reason-picker, .toast { animation: none; }
}
