/* === Flexoki Light Theme === */
:root {
  --fl-paper: #FFFCF0;
  --fl-bg: #F2F0E5;
  --fl-ui: #E6E4D9;
  --fl-ui-2: #DAD8CE;
  --fl-tx: #100F0F;
  --fl-tx-2: #6F6E69;
  --fl-tx-3: #B7B5AC;
  --fl-red: #AF3029;
  --fl-orange: #BC5215;
  --fl-yellow: #AD8301;
  --fl-green: #66800B;
  --fl-cyan: #24837B;
  --fl-blue: #205EA6;
  --fl-purple: #5E409D;
  --fl-magenta: #A02F6F;

  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1.5rem;
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--fl-bg);
  color: var(--fl-tx);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* === Layout: mobile-first single column === */
#note-app {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 100dvh;
}

/* === iPhone Lockscreen Preview === */
#wallpaper-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
}

#wallpaper-canvas {
  position: relative;
  width: 100%;
  max-width: 440px;
  container-type: inline-size;
  overflow: hidden;
  border-radius: var(--phone-corner-radius-h) / var(--phone-corner-radius-v);
  box-shadow:
    0 1px 3px rgba(0,0,0,0.08),
    0 8px 24px rgba(0,0,0,0.12),
    0 24px 60px rgba(0,0,0,0.16);
}

/* === Lockscreen Zones (all zones visible) === */
.zone {
  position: absolute;
  left: 0;
  width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
}
/* The zones with content leave a margin at both sides */
[data-zone="widget_row"],
[data-zone="text_area"],
[data-zone="notification"] {
  left: 4%;
  width: 92%;
}

/* Status bar — Dynamic Island pill */
[data-zone="status_bar"] {
  display: flex;
  align-items: center;
  justify-content: center;
}
[data-zone="status_bar"]::after {
  content: "";
  width: 32%;
  height: 60%;
  max-height: 36px;
  min-height: 16px;
  background: #1a1a1a;
  border-radius: 50px;
}

/* Date row */
[data-zone="date_row"] {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  font-size: var(--date-font);
  font-weight: 600;
  color: rgba(0, 0, 0, 0.65);
  letter-spacing: 0.02em;
  transition: color 0.15s;
  padding-bottom: 0;
}
/* Clock — SF Pro Display light style */
[data-zone="clock"] {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  font-family: -apple-system, "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  font-size: var(--clock-font);
  font-weight: 300;
  color: rgba(0, 0, 0, 0.40);
  letter-spacing: -0.01em;
  line-height: 1;
  transition: color 0.15s;
}

/* Widget zone — row of individual widget placeholders */
.widget-zone {
  display: flex;
  gap: var(--widget-gap);
  align-items: stretch;
  padding: var(--widget-padding) 0;
  background: transparent;
  border: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
}
.widget-placeholder {
  flex: 1;
  border-radius: var(--widget-corner-radius);
  background: rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  transition: background 0.15s;
}
.widget-placeholder.half {
  flex: 2;
}

/* Text area zone — where user content goes */
[data-zone="text_area"] {
  padding: 0;
  line-height: 1.45;
  font-size: var(--editor-font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Trix hook inside text area — thin dashed border to indicate editable */
#text-area-zone #trix-hook {
  width: 100%;
  flex: 1 1 0%;
  min-height: 0;
  position: relative;
}

/* Content display hidden during editing, visible for PNG capture */
#text-area-zone #content-display {
  display: none;
  width: 100%;
  flex: 1 1 0%;
  min-height: 0;
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  font-size: var(--editor-font);
  line-height: 1.45;
  padding: var(--trix-padding-y) var(--trix-padding-x);
  color: rgba(0, 0, 0, 0.85);
  overflow-y: hidden;
}

/* Bottom controls — flashlight/camera circles */
[data-zone="bottom_controls"] {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0 12%;
}
[data-zone="bottom_controls"]::before,
[data-zone="bottom_controls"]::after {
  content: "";
  width: var(--bottom-circle-size);
  height: var(--bottom-circle-size);
  background: rgba(0, 0, 0, 0.05);
  border-radius: 50%;
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  border: var(--bottom-circle-border) solid rgba(0, 0, 0, 0.04);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

/* Home indicator — thin dark pill */
[data-zone="home_indicator"] {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--home-indicator-padding);
}
[data-zone="home_indicator"]::after {
  content: "";
  width: var(--home-indicator-width);
  height: var(--home-bar-height);
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--home-indicator-pill-radius);
  transition: background 0.15s;
}

/* === Dark Wallpaper Adaptations === */
#wallpaper-canvas[data-theme="dark"] [data-zone="date_row"] {
  color: rgba(255, 255, 255, 0.7);
}

#wallpaper-canvas[data-theme="dark"] [data-zone="clock"] {
  color: rgba(255, 255, 255, 0.40);
}

#wallpaper-canvas[data-theme="dark"] .widget-zone {
  background: transparent;
}
#wallpaper-canvas[data-theme="dark"] .widget-placeholder {
  background: rgba(255, 255, 255, 0.12);
}

#wallpaper-canvas[data-theme="dark"] .notification-zone {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

#wallpaper-canvas[data-theme="dark"] [data-zone="bottom_controls"]::before,
#wallpaper-canvas[data-theme="dark"] [data-zone="bottom_controls"]::after {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

#wallpaper-canvas[data-theme="dark"] [data-zone="home_indicator"]::after {
  background: rgba(255, 255, 255, 0.45);
}

#wallpaper-canvas[data-theme="dark"] trix-editor {
  border: none;
  color: rgba(255, 255, 255, 0.9);
}

#wallpaper-canvas[data-theme="dark"] #content-display {
  color: rgba(255, 255, 255, 0.9);
}
#wallpaper-canvas[data-theme="dark"] trix-editor:focus {
  border: 1px solid rgba(255, 255, 255, 0.1);
}
#wallpaper-canvas[data-theme="dark"] trix-editor:empty::before {
  color: rgba(255, 255, 255, 0.3);
}

/* === Capture Mode: hide chrome zones, editor and dev overlay for clean PNG export === */
.capture-mode [data-zone]:not([data-zone="text_area"]),
.capture-mode #trix-hook,
.capture-mode trix-toolbar,
.capture-mode #ref-overlay {
  display: none !important;
}
/* The sanitized copy of the note stands in for the editor */
.capture-mode #content-display {
  display: block !important;
}
.capture-mode {
  border-radius: 0 !important;
  box-shadow: none !important;
}

/* === Loading Skeleton: stands in for the zones around the note until the browser has restored it === */
#note-app[data-note-restored-value="true"] .loading-skeleton,
#note-app[data-note-restored-value="false"] [data-zone]:not([data-zone="text_area"]) {
  display: none;
}
.loading-skeleton {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--fl-ui) 25%, var(--fl-ui-2) 50%, var(--fl-ui) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-lg);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* === Settings Panel === */
.settings-panel {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* App title */
.app-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--fl-tx);
  letter-spacing: -0.02em;
  text-align: center;
}

/* The settings form adds no box: its controls line up with the title and the download button */
#note-form {
  display: contents;
}
/* A setting is a radio inside the label that shows it. The label looks like a button. */
#note-form input[type="radio"],
.dev-toggle-btn input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
#note-form label,
.dev-toggle-btn {
  display: block;
  line-height: normal;
  text-align: center;
}
#note-form label:has(:focus-visible) {
  outline: 2px solid var(--fl-blue);
  outline-offset: 1px;
}

.settings-panel select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--fl-ui-2);
  border-radius: var(--radius-sm);
  background: var(--fl-paper);
  color: var(--fl-tx);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}
.settings-panel select:focus {
  outline: 2px solid var(--fl-blue);
  outline-offset: 1px;
}

/* Position toggle */
.position-toggle,
.settings-panel .download-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--fl-ui-2);
  border-radius: var(--radius-sm);
  background: var(--fl-paper);
  color: var(--fl-tx);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.position-toggle:hover,
.settings-panel .download-btn:hover {
  background: var(--fl-ui);
  border-color: var(--fl-tx-3);
}

/* Alignment controls */
.alignment-controls {
  display: flex;
  gap: 0.375rem;
}

.alignment-controls label {
  flex: 1;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--fl-ui-2);
  border-radius: var(--radius-sm);
  background: var(--fl-paper);
  color: var(--fl-tx-2);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.alignment-controls label:has(:checked) {
  background: var(--fl-tx);
  color: var(--fl-paper);
  border-color: var(--fl-tx);
}

/* Color picker swatches */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.swatch:hover {
  transform: scale(1.1);
}
.swatch:has(:checked) {
  border-color: var(--fl-tx);
  box-shadow: 0 0 0 2px var(--fl-paper), 0 0 0 4px var(--fl-tx);
}

/* Download button — prominent */
.download-btn {
  background: var(--fl-tx) !important;
  color: var(--fl-paper) !important;
  border-color: var(--fl-tx) !important;
  font-weight: 600;
  text-align: center;
}
.download-btn:hover {
  opacity: 0.9;
}

/* === Trix inside canvas: transparent, fills zone, borderless === */
#wallpaper-canvas trix-editor {
  background: transparent;
  border: none;
  border-radius: var(--trix-corner-radius);
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: var(--trix-padding-y) var(--trix-padding-x);
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  font-size: var(--editor-font);
  color: rgba(0, 0, 0, 0.85);
  line-height: 1.45;
  overflow-y: auto;
}
#wallpaper-canvas trix-editor:focus {
  outline: none;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
#wallpaper-canvas trix-editor:empty::before {
  content: "Write your note here...";
  color: rgba(0, 0, 0, 0.25);
  font-style: italic;
}

/* The toolbar offers bold, italic and bullets */
trix-toolbar .trix-button-group--file-tools,
trix-toolbar .trix-button-group--history-tools,
trix-toolbar .trix-button--icon-quote,
trix-toolbar .trix-button--icon-code,
trix-toolbar .trix-button--icon-link,
trix-toolbar .trix-button--icon-strike,
trix-toolbar .trix-button--icon-number-list,
trix-toolbar .trix-button--icon-decrease-nesting-level,
trix-toolbar .trix-button--icon-increase-nesting-level {
  display: none;
}

/* Trix toolbar: hidden by default, shown via JS on selection */
#wallpaper-canvas trix-toolbar {
  display: none;
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

/* Floating toolbar state — escapes overflow:hidden via position:fixed */
#wallpaper-canvas trix-toolbar.floating {
  display: block !important;
  position: fixed;
  z-index: 9999;
  background: var(--fl-paper);
  border: 1px solid var(--fl-ui-2);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 0.25rem;
}

/* === Notification zone — iOS-style notification banner placeholder === */
.notification-zone {
  border-radius: var(--notification-corner-radius);
  background: rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(25px) saturate(170%);
  -webkit-backdrop-filter: blur(25px) saturate(170%);
  border: 0.5px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

/* === Dev Overlay === */
#ref-overlay {
  pointer-events: none;
}

#ref-overlay img {
  display: block;
}

.dev-toggle-btn {
  display: block;
  margin: 0 auto 0.5rem;
  padding: 0.25rem 1.5rem;
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 0.25rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.dev-toggle-btn:hover {
  opacity: 1;
}

/* === Desktop / Tablet: responsive grid layout === */
@media (min-width: 768px) {
  #note-app {
    display: grid;
    grid-template-columns: 1fr 1fr;
    max-width: 960px;
    gap: 2rem;
    padding: 2rem;
    align-items: start;
    min-height: 100vh;
  }

  /* Preview takes right column */
  #wallpaper-preview {
    grid-column: 2;
    grid-row: 1 / -1;
    align-self: center;
  }

  /* Settings in left column — golden ratio vertical position */
  .settings-panel {
    grid-column: 1;
    margin-top: calc(38vh - 10rem);
  }

  .app-title {
    font-size: 2rem;
    margin-bottom: 1rem;
  }
}
