:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111111;
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.45);
  --line: rgba(255, 255, 255, 0.12);
  --cell: #1a1a1a;
  --cell-full: #3a3a3a;
  --header: rgba(255, 255, 255, 0.85);
  --topnav-bg: #111111;
  --theme-color: #111111;
  /* Match mid-head: 12px type + 6+4 padding */
  --title-bar-h: calc(12px * 1.3 + 10px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --third: calc(100vw / 3);
}

/* Lightest neutral grey that still keeps white text readable */
html[data-theme="light"] {
  color-scheme: dark;
  --bg: #6e6e6e;
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.7);
  --line: rgba(255, 255, 255, 0.22);
  --cell: #636363;
  --cell-full: #555555;
  --header: #ffffff;
  --topnav-bg: #6e6e6e;
  --theme-color: #6e6e6e;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
}

/* —— Topnav (all zoom levels) —— */
.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  height: calc(var(--safe-top) + var(--title-bar-h));
  padding-top: var(--safe-top);
  padding-left: 8px;
  padding-right: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--topnav-bg);
  border-bottom: 1px solid var(--line);
  color: #ffffff;
}

.auth-guest,
.auth-user {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  height: 100%;
}

.auth-guest[hidden],
.auth-user[hidden],
.auth-btn[hidden] {
  display: none !important;
}

.auth-email {
  width: 100%;
  height: calc(var(--title-bar-h) - 6px);
  margin: 0;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #ffffff;
  font: inherit;
  font-size: 12px;
  outline: none;
  box-shadow: none;
}

.auth-email::placeholder {
  color: var(--muted);
}

.auth-email.auth-email-invalid {
  color: #ffb4b4;
}

.auth-email-label {
  display: block;
  width: 100%;
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.auth-btn {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  height: calc(var(--title-bar-h) - 6px);
  margin: 0;
  padding: 0 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #ffffff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}

.auth-btn.auth-btn-muted,
.auth-btn:disabled {
  color: var(--muted);
  cursor: default;
}

.auth-code-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.auth-code-row[hidden] {
  display: none !important;
}

.auth-code {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(var(--title-bar-h) - 6px);
  margin: 0;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: #ffffff;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.12em;
  outline: none;
}

.theme-toggle {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  width: var(--title-bar-h);
  height: var(--title-bar-h);
  border: 0;
  background: transparent;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.theme-toggle-img {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
  pointer-events: none;
  /* Same white glyph in both modes */
  filter: invert(1);
}

html[data-theme="light"] .theme-toggle-img {
  transform: scaleX(-1);
}

#app {
  height: 100%;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.view {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-top: calc(var(--safe-top) + var(--title-bar-h));
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  color: var(--fg);
  transform: translate3d(0, 0, 0);
  z-index: 1;
  visibility: hidden;
  pointer-events: none;
}

.view.is-current {
  visibility: visible;
  pointer-events: auto;
  z-index: 3;
}

.view.is-under {
  visibility: visible;
  pointer-events: none;
  z-index: 2;
}

.view.is-dragging {
  overflow: hidden;
}

.view.slide-animating {
  transition: transform 0.34s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.edge-zone {
  display: none;
}

/* —— Month —— */
.month-block {
  padding: 12px 8px 28px;
}

.month-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 8px 4px 12px;
  color: var(--fg);
}

.dow-row,
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.dow-row {
  margin-bottom: 6px;
}

.dow {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 0;
}

.m-cell {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 0;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--cell);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #ffffff;
  user-select: none;
  cursor: pointer;
}

.m-cell.empty {
  background: transparent;
  border-color: transparent;
}

.m-cell.has {
  background: var(--cell-full);
  font-weight: 600;
}

.m-cell.today {
  outline: 1px solid rgba(255, 255, 255, 0.55);
}

.m-cell.is-selected {
  outline: 2px solid #ffffff;
  background: #2a2a2a;
}

html[data-theme="light"] .m-cell.is-selected {
  background: #555555;
}

/* —— Mid —— */
#view-mid {
  overflow-x: hidden;
}

.mid-grid {
  display: grid;
  grid-template-columns: repeat(3, var(--third));
  width: 100vw;
}

.mid-cell {
  width: var(--third);
  height: var(--third);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.mid-cell.has {
  background: #161616;
}

html[data-theme="light"] .mid-cell.has {
  background: #5c5c5c;
}

.mid-cell.is-selected {
  outline: 2px solid #ffffff;
  outline-offset: -2px;
  background: #222222;
  z-index: 1;
}

html[data-theme="light"] .mid-cell.is-selected {
  background: #505050;
}

.mid-cell.is-selected .mid-head {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.mid-head {
  flex: 0 0 auto;
  height: var(--title-bar-h);
  box-sizing: border-box;
  padding: 6px 8px 4px;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--header);
  border-bottom: 1px solid var(--line);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
}

.mid-head.today {
  color: #ffffff;
}

.mid-body {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  border: 0;
  resize: none;
  background: transparent;
  color: #ffffff;
  font: inherit;
  font-size: 16px;
  line-height: 1.3;
  padding: 6px 8px;
  outline: none;
  overflow: auto;
}

.mid-body::placeholder {
  color: var(--muted);
}

/* —— Day —— */
#view-day {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.day-page-header {
  flex: 0 0 auto;
  height: var(--title-bar-h);
  box-sizing: border-box;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: #ffffff;
  border-bottom: 1px solid var(--line);
  user-select: none;
  display: flex;
  align-items: center;
}

.day-page-editor {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  resize: none;
  background: var(--bg);
  color: #ffffff;
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
  padding: 14px 16px;
  outline: none;
}

.day-page-editor::placeholder {
  color: var(--muted);
}
