/* ============================================================
   Deep Work — visual system
   ============================================================ */

:root {
  /* type */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  --text-xs:   0.6875rem;
  --text-sm:   0.8125rem;
  --text-md:   0.9375rem;
  --text-lg:   1.125rem;
  --clock-big:   clamp(5rem, 19vw, 15rem);
  --clock-small:  clamp(3rem, 9vw, 4.75rem);
  --clock-corner: 1.75rem;

  /* space */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4.5rem;

  --cell: 11px;

  --radius:    10px;
  --radius-lg: 16px;

  /* color — light */
  --bg:        #FAF9F6;
  --surface:   #FFFFFF;
  --ink:       #16161A;
  --ink-2:     #56555F;
  --ink-3:     #9A9AA2;
  --line:      #E6E4DE;
  --line-2:    #F0EEE9;

  --accent:       #C2410C;   /* focus */
  --accent-soft:  #FDEDE4;
  --accent-break: #3F6E5E;   /* break  */
  --break-soft:   #E7F0EC;

  --shadow: 0 1px 2px rgba(20,20,24,.04), 0 8px 24px -8px rgba(20,20,24,.10);
  --shadow-lg: 0 2px 4px rgba(20,20,24,.05), 0 24px 60px -16px rgba(20,20,24,.20);

  --ease: cubic-bezier(.22, 1, .36, 1);
}

[data-theme="dark"] {
  --bg:      #121212;
  --surface: #1A1A1A;
  --ink:     #F2F1EC;
  --ink-2:   #A8A7A1;
  --ink-3:   #6E6D69;
  --line:    #2A2A29;
  --line-2:  #212120;

  --accent:       #F0794A;
  --accent-soft:  #2E1C13;
  --accent-break: #6FA893;
  --break-soft:   #16251F;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -8px rgba(0,0,0,.5);
  --shadow-lg: 0 2px 4px rgba(0,0,0,.5), 0 24px 60px -16px rgba(0,0,0,.7);
}

/* break state repaints the accent — one variable, whole app follows */
[data-state="break"] {
  --accent:      var(--accent-break);
  --accent-soft: var(--break-soft);
  --bg: color-mix(in srgb, #FAF9F6 93%, var(--accent-break));
}
[data-theme="dark"][data-state="break"] {
  --bg: color-mix(in srgb, #121212 92%, var(--accent-break));
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color .5s var(--ease), color .5s var(--ease);
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

svg { fill: currentColor; }
svg.is-hidden { display: none; }

/* ============================================================
   Optional background layer
   ============================================================ */

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0;
  transition: opacity .6s var(--ease);
  pointer-events: none;
}
[data-bg="color"] .bg { opacity: 1; background: #DCD9CE; }
[data-theme="dark"][data-bg="color"] .bg { background: #1B2320; }
[data-bg="image"] .bg {
  opacity: 1;
  background: url("https://images.unsplash.com/photo-1501004318641-b39e6451bec6?auto=format&fit=crop&w=2000&q=70") center/cover no-repeat;
}
[data-bg="image"] .bg::after {
  content: "";
  position: absolute; inset: 0;
  background: var(--bg);
  opacity: .82;
  backdrop-filter: blur(2px);
}

/* ============================================================
   App shell
   ============================================================ */

.app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-6);
}

.brand {
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.bar__actions { display: flex; gap: var(--s-1); }

.iconbtn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  color: var(--ink-3);
  transition: color .2s, background-color .2s;
}
.iconbtn:hover { color: var(--ink); background: var(--line-2); }

.bar--foot { justify-content: center; gap: var(--s-6); }

.stat { font-size: var(--text-sm); color: var(--ink-3); }
.stat b { font-weight: 500; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.stat--muted { color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ============================================================
   Stage — label / clock / track / presets / actions
   ============================================================ */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-5);
  padding: var(--s-6);
}

.stage__label {
  margin: 0;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent);
  transition: color .5s var(--ease);
}

.clock { line-height: 1; }

.clock__digits {
  display: block;
  font-size: var(--clock-big);
  font-weight: 300;
  letter-spacing: -.045em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  color: var(--ink);
  line-height: .92;
}

.track {
  width: min(42vw, 420px);
  height: 2px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.track__fill {
  display: block;
  height: 100%;
  width: calc(var(--pct) * 100%);
  background: var(--accent);
  transition: width 1s linear, background-color .5s var(--ease);
}

.presets { display: flex; gap: var(--s-2); }

.chip {
  padding: var(--s-2) var(--s-4);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  background: var(--surface);
  transition: border-color .2s, color .2s, background-color .2s;
}
.chip span { color: var(--ink-3); font-weight: 400; margin-left: 1px; }
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip.is-on { border-color: var(--ink); color: var(--ink); }
.chip.is-on span { color: var(--ink-2); }

.actions { display: flex; align-items: center; gap: var(--s-3); }

.btn {
  padding: var(--s-3) var(--s-6);
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: .01em;
  transition: opacity .2s, background-color .2s, color .2s, border-color .2s;
}
.btn--primary { background: var(--ink); color: var(--bg); }
.btn--primary:hover { opacity: .85; }
.btn--ghost { color: var(--ink-3); }
.btn--ghost:hover { color: var(--ink); }
.btn--danger { color: var(--ink-3); }
.btn--danger:hover { color: var(--accent); }

/* corner-widget-only controls */
.widget__controls { display: none; gap: 2px; }
.widget__btn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--ink-2);
}
.widget__btn:hover { color: var(--ink); background: var(--line-2); }
.widget__btn .icon-play { margin-left: 1px; }

/* ---- state: idle ---- */
[data-state="idle"] .stage__label { color: var(--ink-3); }
[data-state="idle"] .track { opacity: 0; }
[data-state="idle"] .actions .btn--ghost { display: none; }
[data-state="idle"] #primary { padding-inline: var(--s-7); }

/* ---- state: paused ---- */
[data-state="paused"] .clock__digits { color: var(--ink-3); }
[data-state="paused"] .stage__label { color: var(--ink-3); }

/* ---- state: focus / break hide preset row while counting ---- */
[data-state="focus"] .presets,
[data-state="break"] .presets,
[data-state="paused"] .presets { display: none; }

/* ============================================================
   Layout: small
   ============================================================ */

[data-layout="small"] .stage { gap: var(--s-4); }
[data-layout="small"] .clock__digits { font-size: var(--clock-small); letter-spacing: -.03em; }
[data-layout="small"] .track { width: min(70vw, 260px); }
[data-layout="small"] .stage {
  margin: auto;
  padding: var(--s-7) var(--s-8);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* ============================================================
   Layout: corner — floating widget, everything else gone
   ============================================================ */

[data-layout="corner"] .bar,
[data-layout="corner"] .presets,
[data-layout="corner"] .actions,
[data-layout="corner"] .track { display: none; }

[data-layout="corner"] .app { display: block; min-height: 0; }

[data-layout="corner"] .stage {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  flex-direction: row;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
}
[data-layout="corner"] .stage__label {
  font-size: 0;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  transition: background-color .5s var(--ease);
}
[data-layout="corner"] .clock__digits {
  font-size: var(--clock-corner);
  font-weight: 400;
  letter-spacing: -.02em;
}
[data-layout="corner"] .widget__controls { display: flex; }

/* ============================================================
   Sheets (settings / year progress)
   ============================================================ */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(6px);
  visibility: hidden;
  opacity: 0;
}
.sheet.is-open { visibility: visible; opacity: 1; }

.sheet__panel {
  width: min(100%, 420px);
  max-height: 86vh;
  overflow-y: auto;
  padding: var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.sheet__panel--wide { width: min(100%, 880px); }

.sheet__head { display: flex; align-items: center; justify-content: space-between; }
.sheet__head h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 500;
  letter-spacing: -.01em;
}

.sheet__note { margin: 0; font-size: var(--text-xs); color: var(--ink-3); }
.sheet__note--keys { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.sheet__note--keys kbd {
  font: inherit;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--line-2);
  color: var(--ink-2);
}

.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field--row { flex-direction: row; align-items: center; justify-content: space-between; }
.field--sub { margin-top: calc(var(--s-4) * -1); }

.field__label { font-size: var(--text-sm); color: var(--ink-2); }

.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--line-2);
  border-radius: var(--radius);
  align-self: flex-start;
}
.seg__opt {
  padding: 6px var(--s-4);
  border-radius: 7px;
  font-size: var(--text-sm);
  color: var(--ink-3);
  transition: background-color .2s, color .2s;
}
.seg__opt:hover { color: var(--ink); }
.seg__opt.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg--sm .seg__opt { padding: 5px var(--s-3); font-size: var(--text-xs); }

.switch {
  width: 38px; height: 22px;
  padding: 3px;
  border-radius: 999px;
  background: var(--line);
  transition: background-color .25s var(--ease);
}
.switch span {
  display: block;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  transition: transform .25s var(--ease);
}
.switch.is-on { background: var(--accent); }
.switch.is-on span { transform: translateX(16px); }

.input {
  width: 100%;
  padding: var(--s-3) var(--s-4);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .2s;
}
.input::placeholder { color: var(--ink-3); }
.input:focus { border-color: var(--ink-3); }

/* ============================================================
   Year heatmap
   ============================================================ */

.summary { display: flex; gap: var(--s-7); }
.summary__item { display: flex; flex-direction: column; }
.summary__item b {
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.summary__item span { font-size: var(--text-xs); color: var(--ink-3); }

.heat { display: flex; flex-direction: column; gap: var(--s-2); overflow-x: auto; }

.heat__months {
  display: grid;
  gap: 3px;
  margin-left: calc(22px + var(--s-2));
  font-size: var(--text-xs);
  color: var(--ink-3);
  line-height: 1.2;
}
.heat__months span { white-space: nowrap; }

.heat__body { display: flex; gap: var(--s-2); }

.heat__days {
  display: grid;
  grid-template-rows: repeat(7, var(--cell));
  gap: 3px;
  width: 22px;
  font-size: var(--text-xs);
  line-height: var(--cell);
  color: var(--ink-3);
}
.heat__days span:nth-child(1) { grid-row: 1; }
.heat__days span:nth-child(2) { grid-row: 3; }
.heat__days span:nth-child(3) { grid-row: 5; }

.heat__grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cell));
  gap: 3px;
}

.heat__grid i, .heat__legend i {
  display: block;
  width: var(--cell); height: var(--cell);
  border-radius: 2px;
  background: var(--line-2);
}
.heat__grid i.is-blank { visibility: hidden; }
.heat__grid i.is-future { opacity: .4; }
.heat__grid i[data-lvl="0"], .heat__legend i[data-lvl="0"] { background: var(--line-2); border: 1px solid var(--line); }
.heat__grid i[data-lvl="1"], .heat__legend i[data-lvl="1"] { background: color-mix(in srgb, var(--accent) 22%, var(--bg)); }
.heat__grid i[data-lvl="2"], .heat__legend i[data-lvl="2"] { background: color-mix(in srgb, var(--accent) 45%, var(--bg)); }
.heat__grid i[data-lvl="3"], .heat__legend i[data-lvl="3"] { background: color-mix(in srgb, var(--accent) 70%, var(--bg)); }
.heat__grid i[data-lvl="4"], .heat__legend i[data-lvl="4"] { background: var(--accent); }

.heat__legend {
  display: flex;
  align-items: center;
  gap: 3px;
  align-self: flex-end;
  font-size: var(--text-xs);
  color: var(--ink-3);
}
.heat__legend span:first-child { margin-right: var(--s-1); }
.heat__legend span:last-child { margin-left: var(--s-1); }

/* ============================================================
   Reduced motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 640px) {
  .bar { padding: var(--s-4); }
  .bar--foot { flex-direction: column; gap: var(--s-1); }
  .summary { gap: var(--s-5); }
  [data-layout="small"] .stage { padding: var(--s-6); }
}
