:root {
  --bg: #0e0e0e;
  --surface: #141414;
  --surface2: #1c1c1c;
  --border: #262626;
  --border2: #333;
  --text: #e8e4dc;
  --muted: #5a5a5a;
  --muted2: #888;
  --peak:     #c8f072;
  --focus:    #7eb8f7;
  --meetings: #f78eb8;
  --admin:    #f7c97e;
  --buffer:   #2e2e2e;
  --buffer-text: #666;
}

* { margin:0; padding:0; box-sizing:border-box; }

/* Centre the app with side margins on wide screens */
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

#root {
  width: min(100%, 1024px);
}

/* App shell — grid container */
.app {
  width: 100%;
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  grid-template-rows: 64px 1fr;
  height: 100vh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

/* ── HEADER ─────────────────────────────────────────────────────── */
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  padding: 0 2rem;
  border-bottom: 1px solid var(--border);
  gap: 2rem;
}

header h1 {
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.day-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

/* Small arrow buttons */
.day-nav button {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted2);
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.day-nav button:hover { border-color: var(--text); color: var(--text); }

.day-display {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  min-width: 180px;
  text-align: center;
}

.day-sub {
  color: var(--muted);
  font-size: 0.65rem;
  margin-top: 1px;
}

/* Today button — override the generic .day-nav button sizing */
.today-btn {
  width: auto !important;
  height: auto !important;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted2);
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: all 0.15s;
}
.today-btn:hover { border-color: var(--peak); color: var(--peak); }

.gen-btn {
  margin-left: auto;
  background: var(--peak);
  color: #0e0e0e;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  transition: opacity 0.15s;
}
.gen-btn:hover { opacity: 0.85; }

/* ── LEFT PANEL — BLOCK PALETTE ─────────────────────────────────── */
.palette {
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.palette-section h3 {
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
  padding-left: 0.25rem;
}

.palette-block {
  border-radius: 8px;
  padding: 0.75rem 1rem;
  cursor: grab;
  font-size: 0.72rem;
  font-weight: 500;
  color: #111;
  margin-bottom: 0.4rem;
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.palette-block:active { cursor: grabbing; }
.palette-block:hover { transform: translateX(3px); box-shadow: -3px 0 0 currentColor; }
.palette-block.peak     { background: var(--peak); }
.palette-block.focus    { background: var(--focus); }
.palette-block.meetings { background: var(--meetings); }
.palette-block.admin    { background: var(--admin); }
.palette-block.buffer   { background: var(--buffer); color: var(--muted2); }

.palette-block .duration-badge {
  margin-left: auto;
  font-size: 0.6rem;
  opacity: 0.6;
  font-weight: 400;
}

.duration-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.dur-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted2);
  padding: 0.35rem;
  border-radius: 5px;
  cursor: pointer;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  text-align: center;
  transition: all 0.15s;
}
.dur-btn:hover, .dur-btn.active { border-color: var(--peak); color: var(--peak); background: rgba(200,240,114,0.06); }

.intention-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}
.intention-input label {
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 0.5rem;
}
.intention-input input {
  background: none;
  border: none;
  color: var(--text);
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 0.9rem;
  width: 100%;
  outline: none;
}
.intention-input input::placeholder { color: var(--muted); }

/* ── CENTRE — TIMELINE ──────────────────────────────────────────── */
.timeline-wrap {
  overflow-y: auto;
  padding: 1.5rem 1.5rem 4rem;
  position: relative;
  min-width: 280px;
}

/* Max-width on the centre column content */
.timeline {
  position: relative;
  min-height: 800px;
  max-width: 720px;
  margin: 0 auto;
}

.time-row {
  display: grid;
  grid-template-columns: 48px 1fr;
  height: 60px;
  position: relative;
}

.time-row::after {
  content: '';
  position: absolute;
  left: 48px; right: 0;
  top: 0;
  height: 1px;
  background: var(--border);
}

.time-row.half::after { background: var(--border); opacity: 0.3; }

.time-label-cell {
  font-size: 0.6rem;
  color: var(--muted);
  padding-top: 4px;
  text-align: right;
  padding-right: 12px;
  letter-spacing: 0.05em;
}

.drop-zone {
  position: relative;
  cursor: pointer;
}

.drop-zone.drag-over {
  background: rgba(200,240,114,0.04);
}

/* Placed blocks */
.placed-block {
  position: absolute;
  left: 60px;
  right: 8px;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  cursor: grab;
  z-index: 10;
  font-size: 0.72rem;
  font-weight: 500;
  color: #111;
  overflow: hidden;
  transition: box-shadow 0.15s;
  user-select: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.placed-block:active { cursor: grabbing; }
.placed-block:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.4); z-index: 20; }
.placed-block.peak     { background: var(--peak); }
.placed-block.focus    { background: var(--focus); }
.placed-block.meetings { background: var(--meetings); }
.placed-block.admin    { background: var(--admin); }
.placed-block.buffer   { background: var(--buffer); color: var(--muted2); }

.placed-block .block-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.placed-block .block-time  { font-size: 0.6rem; opacity: 0.65; margin-top: 2px; }

.block-delete {
  position: absolute;
  top: 6px; right: 8px;
  background: rgba(0,0,0,0.2);
  border: none;
  color: inherit;
  width: 18px; height: 18px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.6rem;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: 'DM Mono', monospace;
}
.placed-block:hover .block-delete { display: flex; }

/* resize handle */
.resize-handle {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 10px;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.resize-handle::after {
  content: '';
  width: 24px; height: 2px;
  background: rgba(0,0,0,0.25);
  border-radius: 2px;
}

/* drop ghost */
.drop-ghost {
  position: absolute;
  left: 60px; right: 8px;
  border-radius: 8px;
  background: rgba(200,240,114,0.15);
  border: 1px dashed var(--peak);
  pointer-events: none;
  z-index: 5;
  display: none;
}

/* ── RIGHT PANEL — WALLPAPER PREVIEW ────────────────────────────── */
.preview-panel {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-panel-header {
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-panel-header h3 {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.theme-dots {
  display: flex;
  gap: 0.4rem;
}

.theme-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.theme-dot.active { border-color: var(--peak); }

.preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

canvas#wallCanvas {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}

.phone-selector {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.phone-selector label {
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  color: var(--muted2);
  white-space: nowrap;
  letter-spacing: 0.04em;
}
.phone-selector select {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  cursor: pointer;
}
.phone-selector select:focus { outline: none; border-color: var(--peak); }

.dl-btn {
  display: block;
  text-align: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem;
  border-radius: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-decoration: none;
  transition: border-color 0.2s;
}
.dl-btn:hover { border-color: var(--peak); color: var(--peak); }
.cal-btn { background: none; cursor: pointer; }

.hint-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
  font-size: 0.68rem;
  color: var(--muted2);
  line-height: 1.7;
}
.hint-box strong { color: var(--text); }

/* ── SETTINGS ───────────────────────────────────────────────────── */
.settings-open-btn {
  margin-top: 0.9rem;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted2);
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.7rem;
  font-family: inherit;
  text-align: left;
  letter-spacing: 0.04em;
  transition: border-color 0.2s, color 0.2s;
}
.settings-open-btn:hover { border-color: var(--peak); color: var(--peak); }

.settings-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  transition: border-color 0.2s;
}
.settings-back:hover { border-color: var(--peak); color: var(--peak); }

.settings-title {
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  margin: 0;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 640px;
}

.settings-section h3 {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted2);
  margin: 0 0 0.9rem;
}

.settings-block-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.settings-block-icon {
  font-size: 0.9rem;
  width: 1.2rem;
  flex-shrink: 0;
  text-align: center;
}

.settings-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  flex: 1;
  min-width: 0;
  transition: border-color 0.2s;
}
.settings-input:focus { outline: none; border-color: var(--peak); }

.settings-hint-input { color: var(--muted2); flex: 1.4; }

.settings-reset-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted2);
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.72rem;
  font-family: inherit;
  margin-top: 0.4rem;
  transition: border-color 0.2s, color 0.2s;
}
.settings-reset-btn:hover { border-color: var(--peak); color: var(--peak); }

.settings-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.settings-select:focus { outline: none; border-color: var(--peak); }

.setting-row { margin-bottom: 1rem; }
.setting-row:last-child { margin-bottom: 0; }

.setting-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted2);
  margin-bottom: 0.35rem;
}

.settings-filename-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-filename-suffix {
  color: var(--muted2);
  font-size: 0.75rem;
  white-space: nowrap;
}

/* ── DRAG GHOST ─────────────────────────────────────────────────── */
#dragGhost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  font-weight: 500;
  color: #111;
  opacity: 0.9;
  transform: rotate(2deg);
  display: none;
  white-space: nowrap;
}

/* scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ── TAB BAR (mobile only, hidden on desktop) ───────────────────── */
.tab-bar {
  display: none;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted2);
  padding: 0.75rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--peak); border-bottom-color: var(--peak); }

/* ── TAP HINT ────────────────────────────────────────────────────── */
.tap-hint {
  background: rgba(200,240,114,0.08);
  border: 1px solid var(--peak);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.68rem;
  color: var(--peak);
  letter-spacing: 0.04em;
  margin-bottom: 0.75rem;
}
.tap-hint.hidden { display: none; }

/* ── PALETTE TAP SELECTION ───────────────────────────────────────── */
.palette-block.tap-selected {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* ── MOBILE (≤640px) ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  body { overflow: hidden; }

  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 100vh;
    max-width: 100%;
    overflow: hidden;
  }

  header {
    padding: 0 1rem;
    gap: 0.75rem;
    height: 52px;
    flex-shrink: 0;
  }
  header h1 { display: none; }
  .day-display { min-width: 0; font-size: 0.7rem; }
  .day-sub { display: none; }

  .tab-bar { display: flex; }

  /* All panels hidden by default — JS adds .tab-active */
  .palette,
  .timeline-wrap,
  .preview-panel {
    display: none;
    border-right: none;
    border-left: none;
    flex: 1;
    overflow-y: auto;
  }
  .palette.tab-active     { display: flex; }
  .timeline-wrap.tab-active { display: block; }
  .preview-panel.tab-active { display: flex; }

  /* Always-visible delete button on touch */
  .placed-block .block-delete { display: flex; }

  /* Larger resize handle for finger taps */
  .resize-handle { height: 20px; }
}

/* empty state */
.empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}
.empty-state p {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  line-height: 1.6;
}
.empty-state span { font-size: 0.65rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--border2); display: block; margin-top: 0.5rem; }
