* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: #000;
  color: #fff;
  overflow: hidden;
}

body.light-mode {
  background: #f4f4f4;
  color: #111;
}

button {
  font-family: inherit;
  cursor: pointer;
}

a { color: #aaa; text-decoration: none; }

.hidden { display: none !important; }

/* ---------------- Screens ---------------- */
#homeScreen, #noteUI {
  position: absolute;
  inset: 0;
  height: 100vh;
  width: 100vw;
}

/* ---------------- Home screen: Notes-style chrome + drawable canvas ---------------- */
#homeScreen {
  overflow: hidden;
  background: #000;
}
body.light-mode #homeScreen { background: #fff; }

.floating-img {
  position: absolute;
  z-index: 5;
  pointer-events: none; /* taps pass through the decoy chrome to whatever's underneath */
  width: 100%;
  text-align: center;
}
#header-img { top: 0; }
#footer-img { bottom: 0; }
.floating-img img { width: 100%; height: auto; display: block; }

#drawing-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
}

#text-overlay {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 12%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 6;
}
#hidden-input {
  width: 80%;
  padding: 10px;
  font-size: 16px;
  color: transparent;
  background: transparent;
  border: none;
  outline: none;
  caret-color: transparent;
}

/* Invisible tap zones on the home/decoy screen — matches the original
   NTSP exactly: nothing visible, just three transparent hit areas. */
#hidden-button {
  position: absolute;
  top: 0; left: 0;
  width: 70px; height: 30px;
  background: transparent;
  border: none;
  z-index: 10;
}
#clear-button {
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 70px; height: 30px;
  background: transparent;
  border: none;
  z-index: 10;
}
#hidden-topright-button {
  position: absolute;
  top: 0; right: 0;
  width: 70px; height: 70px;
  background: transparent;
  border: none;
  z-index: 100;
}

#cribPreviewStrip {
  position: fixed;
  left: 0; right: 0;
  bottom: 12%;
  z-index: 7;
  display: none;
  overflow-x: auto;
  white-space: nowrap;
  padding: 6px 12px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
}
body.light-mode #cribPreviewStrip { background: rgba(255,255,255,0.7); }
#cribPreviewStrip.show { display: block; }
#cribPreviewStrip span.chip {
  display: inline-block;
  margin-right: 14px;
  color: #fff;
}
body.light-mode #cribPreviewStrip span.chip { color: #111; }

.icon-btn {
  position: fixed;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid #eceef2;
  background: #fff;
  color: #3a3a3c;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
#noteSettingsBtn { top: calc(16px + env(safe-area-inset-top)); right: 16px; }

.backBtn {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  z-index: 500;
  border: 1px solid #eceef2;
  border-radius: 12px;
  background: #fff;
  color: #1c1c1e;
  font-size: 14.5px;
  font-weight: 600;
  padding: 10px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
body.light-mode .backBtn { background: #fff; color: #1c1c1e; }

#appFooter {
  text-align: center;
  font-size: 13px;
  opacity: 0.55;
  margin-top: 30px;
}

/* ---------------- Note screen (always-light, matches Settings) ---------------- */
#noteUI {
  display: none;
  flex-direction: column;
  padding-top: calc(70px + env(safe-area-inset-top));
  padding-bottom: env(safe-area-inset-bottom);
  height: 100vh;
  background: #f4f5f8;
  color: #1c1c1e;
}

#triggerBar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 14px;
}

#triggerInput {
  flex: 1;
  padding: 12px 14px;
  font-size: 15.5px;
  border-radius: 12px;
  border: 1px solid #e6e6ec;
  background: #fff;
  color: #1c1c1e;
  outline: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
body.light-mode #triggerInput {
  background: #fff;
  border-color: #e6e6ec;
  color: #1c1c1e;
}
#triggerInput::placeholder { color: #9a9aa2; }

#micBtn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid #e6e6ec;
  background: #fff;
  color: #0a84ff;
  font-size: 17px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
#micBtn.listening {
  background: linear-gradient(135deg, #ff6b6b, #ee5a52);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(238,90,82,0.4);
}

#noteScroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 40px;
}

.section-title {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8a8a93;
  margin: 18px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e4e4ea;
}
body.light-mode .section-title::after { background: #e4e4ea; }

#cribMenu {
  columns: 2;
  column-gap: 10px;
}
#cribMenu ul { list-style: none; margin: 0; padding: 0; }
#cribMenu li {
  margin: 0 0 6px;
  font-size: var(--crib-size, 13.5px);
  break-inside: avoid;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #eceef2;
  border-radius: 10px;
  padding: 7px 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
#cribMenu li.section-title {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 18px 0 8px;
}
#cribMenu .emoji { font-size: var(--crib-size, 13.5px); flex: 0 0 auto; }
#cribMenu .editable {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #1c1c1e;
}
#cribMenu .editable input {
  width: 100%;
  font-size: inherit;
  background: #f7f7fa;
  color: #1c1c1e;
  border: 1px solid #e0e0e6;
  border-radius: 6px;
  padding: 3px 6px;
}
.edit-btn {
  background: transparent;
  border: none;
  color: #b6b6bd;
  font-size: 12px;
  padding: 2px;
  flex: 0 0 auto;
}
.edit-btn::before { content: "\2699"; }
.edit-btn:hover { color: #0a84ff; }

/* ---------------- Routines section ---------------- */
#routinesHeaderRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 10px;
}
#routinesHeaderRow .section-title { margin: 0; flex: 1; }

.small-btn {
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #48dbfb, #0a84ff);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 13px;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(10,132,255,0.25);
}
body.light-mode .small-btn { background: linear-gradient(135deg, #48dbfb, #0a84ff); color: #fff; }

#routineFolderBackRow { margin-bottom: 10px; }
#routineFolderBackRow .small-btn {
  background: #fff;
  color: #1c1c1e;
  border: 1px solid #eceef2;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

#screenshotList {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.routine-tile-inner {
  background: #fff;
  border: 1px solid #eceef2;
  color: #1c1c1e;
  padding: 18px 24px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
body.light-mode .routine-tile-inner { background: #fff; color: #1c1c1e; }
.routine-tile { cursor: pointer; }

.screenshot-item { position: relative; }
.screenshot-item img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid #eceef2;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  cursor: pointer;
  display: block;
}
.delete-btn, .item-edit-btn {
  position: absolute;
  top: -6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  color: white;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.delete-btn { right: -6px; background: #ff3b30; }
.item-edit-btn { left: -6px; background: #8a8a93; }

.empty-hint { opacity: 0.6; color: #6b6b73; font-size: 13px; padding: 6px 2px; }

/* ---------------- Full-screen reveal ---------------- */
#fullImage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  object-fit: cover;
  z-index: 4;
  display: none;
  background: #000;
}
/* Built-in reveal images are white-on-black line art with no dedicated
   light-mode asset — invert them to black-on-white in light mode. Applied
   only via the .invertible class (set in JS for builtin triggers only),
   never for a user's own Routine photos. */
body.light-mode #fullImage.invertible { filter: invert(1); }

/* ---------------- Modals ---------------- */
body.modal-open::before {
  content: '';
  position: fixed;
  inset: 0;
  backdrop-filter: blur(8px);
  background: rgba(0,0,0,0.45);
  z-index: 1999;
  transition: background 0.15s ease, backdrop-filter 0.15s ease;
}
/* While dragging Header/Footer position or the text-size sliders, fade the
   backdrop + settings card so the live effect on the screen behind is
   actually visible instead of being hidden under the modal. */
body.modal-open.settings-live-preview::before {
  background: rgba(0,0,0,0.05);
  backdrop-filter: blur(1px);
}
body.settings-live-preview #settingsModal {
  opacity: 0.16;
}
.modal {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #111;
  border: 1px solid #444;
  padding: 20px;
  border-radius: 14px;
  z-index: 2000;
  width: 90%;
  max-width: 340px;
  gap: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
body.light-mode .modal { background: #fff; border-color: #ddd; color: #111; }
.modal label { font-size: 13px; margin-top: 8px; color: #ccc; }
body.light-mode .modal label { color: #444; }
.modal input, .modal select {
  padding: 10px;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid #333;
  background: #1a1a1a;
  color: #fff;
}
body.light-mode .modal input, body.light-mode .modal select {
  background: #f4f4f4; color: #111; border-color: #ccc;
}
.modal button { font-size: 15px; padding: 11px 16px; width: 100%; border: none; border-radius: 8px; }
.modal .save-btn { background: linear-gradient(135deg, #26de81, #20bf6b); color: #fff; }
.modal .cancel-btn { background: #333; color: #fff; }
body.light-mode .modal .cancel-btn { background: #e5e5e5; color: #111; }

/* ---------------- Settings modal (always-light card design) ---------------- */
#settingsModal {
  z-index: 2100;
  background: #fbfbfd;
  color: #1c1c1e;
  border: 1px solid #e8e8ee;
  border-radius: 20px;
  padding: 0;
  width: 90%;
  max-width: 360px;
  max-height: 86vh;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,0.35);
  gap: 0;
  transition: opacity 0.15s ease;
}

#settingsModal .settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid #eee;
  background: #fff;
}
#settingsModal .settings-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: #1c1c1e;
}
#settingsModal .close-x {
  align-self: auto;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #f0f0f3;
  border: none;
  color: #666;
  font-size: 13px;
  line-height: 1;
}
#settingsModal .close-x:hover { background: #e6e6ea; }

#settingsModal .settings-scroll {
  overflow-y: auto;
  max-height: calc(86vh - 58px);
  padding: 16px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#settingsModal .settings-section {
  background: #fff;
  border: 1px solid #eceef2;
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
#settingsModal .settings-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a8a93;
  margin-bottom: 10px;
}
#settingsModal .settings-icon { font-size: 14px; }

#settingsModal .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  margin-top: 0;
  padding: 6px 0;
}
#settingsModal .field { padding: 6px 0; }
#settingsModal .row + .field,
#settingsModal .field + .field,
#settingsModal .row + .row {
  margin-top: 2px;
  border-top: 1px solid #f2f2f5;
  padding-top: 10px;
}

#settingsModal label {
  display: block;
  font-size: 13.5px;
  color: #3a3a3c;
  font-weight: 500;
}
body.light-mode #settingsModal label { color: #3a3a3c; }
#settingsModal .hint { font-size: 11px; color: #9a9aa2; margin-top: 4px; text-align: center; }
#settingsModal .hint-inline { font-size: 11px; color: #9a9aa2; font-weight: 400; display: block; margin-top: 2px; }

#settingsModal select {
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid #e0e0e6;
  background: #f7f7fa;
  color: #1c1c1e;
  font-size: 13.5px;
}

#settingsModal input[type="range"] {
  width: 100%;
  margin-top: 8px;
  accent-color: #0a84ff;
  height: 4px;
}

/* iOS-style toggle switches (checkboxes keep their normal checked/change behavior) */
#settingsModal input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 46px;
  height: 27px;
  border-radius: 14px;
  background: #e2e2e7;
  position: relative;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
  transition: background 0.2s ease;
}
#settingsModal input[type="checkbox"]::before {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 23px; height: 23px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.2s ease;
}
#settingsModal input[type="checkbox"]:checked {
  background: linear-gradient(135deg, #34c759, #30b350);
}
#settingsModal input[type="checkbox"]:checked::before {
  transform: translateX(19px);
}

#settingsModal .settings-actions {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#settingsModal .action-btn {
  border: none;
  border-radius: 11px;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  width: 100%;
}
#settingsModal .cycle-btn { background: linear-gradient(135deg, #48dbfb, #0abde3); margin-top: 10px; }
#settingsModal .offline-btn { background: linear-gradient(135deg, #26de81, #20bf6b); }
#settingsModal .copy-btn { background: linear-gradient(135deg, #ff9f43, #ee8a2b); }

#settingsModal .danger-btn {
  background: #fff0f0;
  color: #ff3b30;
  border: 1px solid #ffd6d4;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 600;
  margin-top: 2px;
}
#settingsModal .danger-btn:hover { background: #ffe4e2; }

/* ---------------- Offline caching overlay ---------------- */
#offline-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  backdrop-filter: blur(10px);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #fff;
}
#offline-overlay.show { display: flex; }
.loading-content { text-align: center; padding: 0 20px; }
.loading-title { font-size: 20px; margin-bottom: 20px; font-weight: 600; }
.loading-bar-container {
  width: 260px; height: 8px;
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 auto 15px;
}
.loading-bar {
  height: 100%;
  background: linear-gradient(90deg, #26de81, #48dbfb);
  width: 0%;
  transition: width 0.2s ease;
}
.loading-text { font-size: 13px; opacity: 0.8; }

/* ---------------- License gate overlay ---------------- */
#licenseGate {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #0b0b0d;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.25s ease;
}
#licenseGate.license-gate-hidden { opacity: 0; pointer-events: none; }

.license-card {
  width: 100%;
  max-width: 360px;
  background: #fbfbfd;
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.35);
  color: #1c1c1e;
}

.license-checking { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px 0; }
.license-checking p { margin: 0; font-size: 14px; color: #6e6e73; }
.license-spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid #e2e2e7;
  border-top-color: #0a84ff;
  animation: license-spin 0.8s linear infinite;
}
@keyframes license-spin { to { transform: rotate(360deg); } }

.license-form-wrap { display: none; flex-direction: column; align-items: stretch; }
.license-form-wrap h2 { font-size: 18px; margin: 0 0 4px; text-align: center; }
.license-sub { font-size: 13px; color: #8e8e93; text-align: center; margin: 0 0 18px; }

#licenseCodeInput {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid #e0e0e6;
  background: #f7f7fa;
  color: #1c1c1e;
  font-size: 16px;
  letter-spacing: 1.5px;
  text-align: center;
  text-transform: uppercase;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
#licenseCodeInput:focus { outline: 2px solid #0a84ff33; border-color: #0a84ff; }

.license-error {
  display: none;
  font-size: 12.5px;
  color: #ff3b30;
  text-align: center;
  margin-top: 10px;
  line-height: 1.4;
}

.license-submit-btn {
  margin-top: 16px;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #48dbfb, #0a84ff);
  box-shadow: 0 2px 10px rgba(10,132,255,0.3);
}
.license-submit-btn:disabled { opacity: 0.6; }

