:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #e7edf0;
  --ink: #202124;
  --muted: #64717a;
  --line: #d6dee3;
  --accent: #146b6f;
  --accent-ink: #ffffff;
  --danger: #9f2d35;
  --shadow: 0 18px 40px rgba(20, 45, 55, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.topbar,
.section-head,
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1;
}

h2 {
  font-size: 20px;
  line-height: 1.15;
}

h3 {
  font-size: 15px;
  line-height: 1.2;
}

.eyebrow,
.status-line,
.muted {
  color: var(--muted);
}

.eyebrow,
.status-line {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.block-window {
  margin-top: 6px;
  color: var(--accent);
  font-weight: 800;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 5px 14px rgba(20, 45, 55, 0.06);
}

.entry-panel,
.view {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.entry-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.focus-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-weight: 700;
}

.focus-options {
  display: grid;
  grid-template-columns: repeat(5, 38px);
  gap: 6px;
}

.focus-option,
.tab,
.primary-button,
.category-button,
.new-category button,
dialog menu button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-height: 42px;
}

.focus-option {
  width: 38px;
  height: 38px;
  font-weight: 800;
}

.focus-option.is-active,
.tab.is-active,
.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.category-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.category-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px 12px;
  text-align: left;
  font-weight: 800;
}

.category-button span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swatch {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--swatch);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 16px 0 10px;
}

.tab {
  font-weight: 800;
}

.view {
  display: none;
  padding: 16px;
}

.view.is-active {
  display: block;
}

#datePicker,
.dialog-field select,
.new-category input[type="text"] {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
  color: var(--ink);
}

.grid-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.block-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
}

.block-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f9fbfc;
  overflow: hidden;
}

.block-cell::after {
  content: "";
  position: absolute;
  inset: auto 3px 3px;
  height: 3px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  opacity: var(--focus-opacity, 0);
}

.block-cell.is-filled {
  background: var(--block-color);
  border-color: rgba(32, 33, 36, 0.12);
}

.block-cell.is-due:not(.is-filled) {
  border-color: var(--danger);
  background: #fff3f0;
}

.block-cell.is-selected {
  outline: 3px solid rgba(20, 107, 111, 0.3);
  outline-offset: 2px;
}

.chart-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(92px, 140px) 1fr 54px;
  align-items: center;
  gap: 10px;
}

.chart-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 800;
}

.chart-label span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-track {
  height: 16px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  width: var(--bar-width);
  border-radius: inherit;
  background: var(--bar-color);
}

.chart-time {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.focus-summary {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-weight: 700;
}

dialog {
  width: min(calc(100% - 28px), 520px);
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(18, 20, 20, 0.35);
}

.dialog-content {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.settings-content section {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.small {
  font-size: 13px;
  line-height: 1.35;
}

.dialog-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 0;
}

#clearBlockButton {
  color: var(--danger);
}

.category-editor {
  display: grid;
  gap: 8px;
}

.category-edit-row,
.new-category {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(96px, auto);
  gap: 8px;
  align-items: center;
}

.data-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.data-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
  font-weight: 800;
}

.category-edit-row input[type="color"],
.new-category input[type="color"] {
  width: 44px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.category-edit-row input[type="text"] {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

.delete-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
  font-weight: 900;
}

@media (min-width: 720px) {
  .entry-panel {
    grid-template-columns: 1fr 260px;
  }

  .category-grid {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .category-grid.compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding-inline: 12px;
  }

  h1 {
    font-size: 29px;
  }

  .entry-panel,
  .view {
    padding: 14px;
  }

  .block-grid {
    gap: 4px;
  }

  .chart-row {
    grid-template-columns: minmax(78px, 98px) 1fr 44px;
  }
}
