:root {
  color-scheme: dark;
  --bg: #232427;
  --surface: #2e3034;
  --border: #3c3f44;
  --text: #e4e4e6;
  --muted: #9a9ca1;
  --accent: #8fb4d9;
  --danger: #e5736b;
}

:root[data-theme="black"] {
  --bg: #000000;
  --surface: #121212;
  --border: #2a2a2a;
  --text: #e6e6e6;
  --muted: #8a8a8a;
  --accent: #b0b0b0;
}

:root[data-theme="blue"] {
  --bg: #121a2b;
  --surface: #1b2540;
  --border: #2a3658;
  --text: #e3e8f4;
  --muted: #8e9ab8;
  --accent: #6ea8fe;
}

:root[data-theme="orange"] {
  --bg: #1f1611;
  --surface: #2c1f17;
  --border: #45301f;
  --text: #f1e6dc;
  --muted: #b09a87;
  --accent: #e8913a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 6px calc(8px + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tabs {
  display: flex;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs a {
  flex: none;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.tabs a:hover {
  color: var(--text);
}

.tabs a[aria-current="page"] {
  color: var(--text);
  background: var(--bg);
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* 16px keeps iOS Safari from zooming in on focus. */
select,
input,
button {
  flex: none;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.topbar form {
  flex: none;
  margin: 0;
}

main {
  padding: 12px calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
}

.empty,
.muted {
  color: var(--muted);
}

a {
  color: var(--accent);
}

.auth {
  max-width: 340px;
  margin: 0 auto;
  padding-top: calc(12vh + env(safe-area-inset-top));
}

.auth h1 {
  margin: 0 0 16px;
  font-size: 22px;
}

.auth form {
  display: grid;
  gap: 12px;
}

.auth label {
  display: grid;
  gap: 4px;
  color: var(--muted);
}

.auth input {
  width: 100%;
  padding: 7px 8px;
  background: var(--surface);
}

.auth button {
  padding: 7px 8px;
  background: var(--surface);
}

.error {
  color: var(--danger);
}

.auth.wide {
  max-width: 720px;
  padding-top: calc(24px + env(safe-area-inset-top));
}

.auth h2 {
  margin: 24px 0 8px;
  font-size: 17px;
}

.account-link {
  flex: none;
  color: var(--muted);
  text-decoration: none;
}

.account-link:hover {
  color: var(--text);
}

.notice {
  color: var(--accent);
}

form.inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.auth form.inline input {
  width: auto;
  flex: 1 1 140px;
}

.users {
  margin: 0;
  padding: 0;
  list-style: none;
}

.users li {
  display: grid;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.push p {
  margin: 0 0 8px;
}

.devices {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.devices li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.badge {
  padding: 1px 6px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 12px;
}

.danger {
  color: var(--danger);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}

.tile {
  position: relative;
  min-height: 84px;
}

.tile a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 100%;
  padding: 10px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

.tile a:hover {
  border-color: var(--accent);
}

.tile img,
.tile-letter {
  width: 32px;
  height: 32px;
  border-radius: 6px;
}

.tile-letter {
  display: grid;
  place-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 600;
}

.tile-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-edit {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}

.tile-edit:hover {
  color: var(--text);
}

.tile-add {
  width: 100%;
  background: transparent;
  border-style: dashed;
  border-radius: 8px;
  color: var(--muted);
  font-size: 22px;
}

dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.tile-form {
  display: grid;
  gap: 12px;
}

.tile-form h2 {
  margin: 0;
  font-size: 17px;
}

.tile-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
}

.tile-form input,
.tile-form select,
.tile-form textarea {
  width: 100%;
  padding: 7px 8px;
}

.field-row {
  display: grid;
  grid-template-columns: 3fr 2fr auto;
  gap: 8px;
}

/* The native picker input lies invisibly over the icon, so a tap opens it directly (also on iOS). */
.cal {
  position: relative;
  align-self: end;
  display: grid;
  place-items: center;
  width: 40px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

.tile-form .cal input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.tile-form button {
  padding: 7px 10px;
}

.tile-form .error {
  margin: 0;
}

/* Narrow screens: tabs get a full row, the account controls a second one. */
@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 4px;
    /* Extra room below the translucent iOS status bar. */
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  .tabs {
    flex: 1 0 100%;
  }

  .account-link {
    flex: 1;
    padding-left: 10px;
  }
}

.group-head {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 16px 0 8px;
}

.tile-group:first-child .group-head {
  margin-top: 4px;
}

.group-head h2 {
  margin: 0;
  font-size: 17px;
}

.group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-color: transparent;
  background: transparent;
  font-size: 17px;
  font-weight: 600;
}

.chevron {
  width: 1em;
  color: var(--muted);
}

.group-count {
  color: var(--muted);
  font-weight: 400;
}

.group-edit {
  width: 28px;
  height: 28px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}

.group-edit:hover {
  color: var(--text);
}

.group-add {
  margin-top: 16px;
  padding: 7px 10px;
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

/* Dragging headings (web/drag.js). touch-action: none keeps touch from scrolling instead. */
.group-toggle {
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.sorting {
  -webkit-user-select: none;
  user-select: none;
  cursor: grabbing;
}

/* Todo items are dragged by their text after a hold on touch, so the list
   still scrolls: no touch-action: none here. */
.todo-item:not(.is-done) .todo-body {
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.tile-group.dragging,
.todo-item.dragging {
  position: relative;
  z-index: 5;
  background: var(--bg);
  opacity: 0.85;
}

.tile-group.drop-before,
.todo-item.drop-before {
  box-shadow: 0 -3px 0 var(--accent);
}

.tile-group.drop-after,
.todo-item.drop-after {
  box-shadow: 0 3px 0 var(--accent);
}

/* Todo */
.todo-list:first-child .group-head {
  margin-top: 4px;
}

.todo-items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}

.todo-item input[type="checkbox"] {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  accent-color: var(--accent);
}

.todo-body {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.todo-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  color: var(--muted);
  font-size: 13px;
}

.todo-desc {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
}

.todo-overdue {
  color: var(--danger);
}

.todo-item.is-done .todo-name {
  color: var(--muted);
  text-decoration: line-through;
}

.todo-add {
  margin-top: 8px;
  padding: 5px 10px;
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

.todo-done {
  margin-top: 8px;
}

.todo-done summary {
  color: var(--muted);
  cursor: pointer;
}

/* Notes: absolutely placed children widen and lengthen the page by themselves,
   so the board scrolls with the page when notes lie beyond the screen. */
.note-add {
  margin-bottom: 12px;
  padding: 7px 10px;
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

.notes-board {
  position: relative;
  min-height: 60vh;
}

.note {
  position: absolute;
  width: 220px;
  border-radius: 6px;
  background: var(--note-bg);
  color: #26262a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  overflow-wrap: anywhere;
}

/* Palette shared by the notes and the swatches in the dialog; keep in sync with notes.Colours. */
.c-yellow {
  --note-bg: #f6e27a;
}

.c-orange {
  --note-bg: #f5b97a;
}

.c-pink {
  --note-bg: #f2a9c0;
}

.c-green {
  --note-bg: #aedb9a;
}

.c-blue {
  --note-bg: #9cc7ee;
}

.note.dragging {
  z-index: 5;
  opacity: 0.9;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

/* The header is the drag handle; touch-action: none lets touch drag at once. */
.note-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 2px 2px 8px;
  border-radius: 6px 6px 0 0;
  background: rgba(0, 0, 0, 0.12);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.note.dragging .note-head {
  cursor: grabbing;
}

.note-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.note .group-edit {
  flex: none;
  color: #26262a;
  opacity: 0.7;
}

.note .group-edit:hover {
  opacity: 1;
}

.note-body {
  padding: 6px 8px 8px;
}

.note-desc {
  margin: 0 0 4px;
  white-space: pre-wrap;
}

.note-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
  font-size: 13px;
}

.note-late {
  padding: 0 5px;
  border-radius: 4px;
  background: #b3261e;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* The note a notification click opened. */
.note.note-focus {
  z-index: 4;
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Note dialog */
.tile-form .hint {
  margin: -6px 0 0;
  font-size: 13px;
  font-weight: 400;
}

.reminders {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 6px 10px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.reminders legend {
  padding: 0 4px;
  color: var(--muted);
}

.tile-form .reminders .hint {
  margin: 0;
}

.reminder-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.reminder-list li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 2px 2px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.reminder-list li.done {
  color: var(--muted);
}

.tile-form .reminder-list button {
  padding: 0 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

/* Without a time the controls are disabled as a group. */
.reminder-controls {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.reminder-controls:disabled {
  opacity: 0.5;
}

.reminder-new {
  display: grid;
  grid-template-columns: 4.5em 1fr auto;
  gap: 8px;
}

.reminder-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tile-form .reminder-quick button {
  padding: 4px 8px;
  font-size: 14px;
}

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

.tile-form .swatch {
  display: block;
  position: relative;
}

.tile-form .swatch input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
}

.swatch span {
  display: block;
  width: 34px;
  height: 34px;
  border: 3px solid transparent;
  border-radius: 6px;
  background: var(--note-bg);
  cursor: pointer;
}

.swatch input:checked + span {
  border-color: var(--text);
}

.swatch input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Whiteboard */
.wb-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.wb-tabs {
  position: relative; /* offsetLeft of the tabs counts from here */
  display: flex;
  flex: 1;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.wb-tabs::-webkit-scrollbar {
  display: none;
}

/* Dragged after a hold on touch, so a swipe still scrolls the strip. */
.wb-tab {
  max-width: 180px;
  padding: 5px 10px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
  background: var(--surface);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.wb-tab[aria-current="true"] {
  color: var(--text);
  border-color: var(--accent);
}

.wb-tab.dragging {
  position: relative;
  z-index: 5;
  opacity: 0.85;
}

.wb-tab.drop-before {
  box-shadow: -3px 0 0 var(--accent);
}

.wb-tab.drop-after {
  box-shadow: 3px 0 0 var(--accent);
}

.wb-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.wb-group {
  display: flex;
  gap: 4px;
}

.wb-tools button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
}

.wb-tools button[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: var(--surface);
}

.wb-tools button:disabled:not(.wb-save) {
  opacity: 0.4;
  cursor: default;
}

.wb-tools .wb-wide {
  width: auto;
  padding: 0 10px;
  font-size: 13px;
}

.wb-tools svg {
  width: 20px;
  height: 20px;
}

/* Keep in sync with PALETTE in whiteboard.js; ink is light on dark, dark on white. */
.wb-tools [data-colour] span {
  width: 20px;
  height: 20px;
  border-radius: 50%;
}

.wb-c0 {
  background: linear-gradient(135deg, #f2f2f2 50%, #111111 50%);
  box-shadow: 0 0 0 1px var(--border);
}

.wb-c1 {
  background: #e53935;
}

.wb-c2 {
  background: #2f80ed;
}

.wb-c3 {
  background: #2e9d4a;
}

.wb-c4 {
  background: #f08c00;
}

.wb-c5 {
  background: #9b51e0;
}

.wb-tools [data-width] span {
  width: 20px;
  border-radius: 4px;
  background: currentColor;
}

.wb-w0 {
  height: 2px;
}

.wb-w1 {
  height: 4px;
}

.wb-w2 {
  height: 8px;
}

.wb-tools .wb-save {
  width: auto;
  padding: 0 10px;
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}

.wb-tools .wb-save:disabled {
  border-color: transparent;
  background: none;
  cursor: default;
}

.wb-tools .wb-save:not(:disabled) {
  color: var(--danger);
}

.wb-text {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.wb-text textarea {
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming in */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
}

.wb-symbols,
.wb-text-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.wb-symbols button {
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
}

.wb-stage {
  display: flex;
  justify-content: center;
}

.wb-sheet {
  position: relative;
  outline: 1px solid var(--border);
}

.wb-sheet canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* The page must not scroll, zoom or select while drawing. */
#wb-live {
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.wb-custom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.wb-bg {
  display: flex;
  gap: 16px;
}

.tile-form .wb-bg label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.tile-form .wb-bg input {
  width: auto;
}

/* A phone on its side: the toolbar becomes a column left of the board, so
   the board gets nearly all the height below the tab strip. */
@media (orientation: landscape) and (max-height: 500px) {
  #whiteboard {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    column-gap: 10px;
    align-items: start;
  }

  .wb-bar,
  #wb-status,
  .wb-text,
  .wb-stage {
    grid-column: 2;
  }

  .wb-tools {
    grid-column: 1;
    grid-row: 1 / span 3;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    margin-bottom: 0;
  }

  .wb-group {
    display: grid;
    grid-template-columns: repeat(3, 36px);
  }

  .wb-tools .wb-wide {
    grid-column: span 3;
    height: 36px;
  }

  .wb-tools .wb-save {
    margin-left: 0;
    padding: 0;
    height: auto;
    white-space: normal;
  }
}

/* Offline: read-only. The banner is shown by offline.js; the controls that
   change data are hidden (the code behind them refuses as well). */
.offline-banner {
  margin: 0;
  padding: 4px calc(12px + env(safe-area-inset-right)) 4px calc(12px + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--accent);
  color: var(--accent);
  text-align: center;
}

html[data-offline] :is(.tile-edit, .group-edit, .tile-add, .group-add, .todo-add, .note-add, #wb-tab-add, #wb-edit, #wb-text, .wb-tools .wb-group) {
  display: none;
}

html[data-offline] .todo-item input[type="checkbox"] {
  pointer-events: none;
  opacity: 0.5;
}
