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

:root {
  --bg: #0d0d0f;
  --bg2: #141416;
  --bg3: #1c1c20;
  --surface: rgba(255, 255, 255, 0.08);
  --surface2: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.18);
  --border2: rgba(255, 255, 255, 0.28);
  --text: #f0ede8;
  --text2: rgba(240, 237, 232, 0.72);
  --text3: rgba(240, 237, 232, 0.44);
  --accent: #c8a96e;
  --accent2: rgba(200, 169, 110, 0.15);
  --red: #e05c5c;
  --green: #5cba82;
  --radius: 14px;
  --font-display: 'DM Serif Display', serif;
  --font-mono: 'DM Mono', monospace;
  --font-sans: 'Instrument Sans', sans-serif;
}

body.t-dark {
  --bg: #0d0d0f;
  --bg2: #141416;
  --bg3: #1c1c20;
  --surface: rgba(255, 255, 255, 0.08);
  --surface2: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.18);
  --border2: rgba(255, 255, 255, 0.28);
  --text: #f0ede8;
  --text2: rgba(240, 237, 232, 0.72);
  --text3: rgba(240, 237, 232, 0.44);
  --accent: #c8a96e;
  --accent2: rgba(200, 169, 110, 0.15);
  --red: #e05c5c;
  --green: #5cba82;
}

body.t-light {
  --bg: #f0ece5;
  --bg2: #e8e3db;
  --bg3: #ddd8cf;
  --surface: rgba(0, 0, 0, 0.06);
  --surface2: rgba(0, 0, 0, 0.11);
  --border: rgba(0, 0, 0, 0.18);
  --border2: rgba(0, 0, 0, 0.28);
  --text: #1a1714;
  --text2: rgba(26, 23, 20, 0.72);
  --text3: rgba(26, 23, 20, 0.46);
  --accent: #8a6430;
  --accent2: rgba(138, 100, 48, 0.12);
  --red: #c0392b;
  --green: #27704a;
}

body.t-glass {
  --bg: transparent;
  --bg2: rgba(255, 255, 255, 0.1);
  --bg3: rgba(255, 255, 255, 0.16);
  --surface: rgba(255, 255, 255, 0.12);
  --surface2: rgba(255, 255, 255, 0.2);
  --border: rgba(255, 255, 255, 0.26);
  --border2: rgba(255, 255, 255, 0.38);
  --text: #f0f4ff;
  --text2: rgba(240, 244, 255, 0.8);
  --text3: rgba(240, 244, 255, 0.5);
  --accent: #a78bfa;
  --accent2: rgba(167, 139, 250, 0.15);
  --red: #f87171;
  --green: #6ee7b7;
}

body.t-bw {
  --bg: #ffffff;
  --bg2: #f5f5f5;
  --bg3: #ebebeb;
  --surface: rgba(0, 0, 0, 0.05);
  --surface2: rgba(0, 0, 0, 0.1);
  --border: rgba(0, 0, 0, 0.22);
  --border2: rgba(0, 0, 0, 0.36);
  --text: #000;
  --text2: rgba(0, 0, 0, 0.72);
  --text3: rgba(0, 0, 0, 0.5);
  --accent: #000;
  --accent2: rgba(0, 0, 0, 0.08);
  --red: #000;
  --green: #000;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  /* FIX: removed 'transition: color .3s' — interpolates all text hues on
     every theme switch, wastes a compositor layer with no visible benefit */
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.theme-dot:focus-visible,
.bg-tab:focus-visible,
.color-swatch:focus-visible,
.grad-preset:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ══ LAYERS ══ */
#bg-img-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity .4s;
}

#bg-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  transition: background .4s;
}

#canvas {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
}

/* ══ TOOLBAR ══ */
#toolbar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border2);
  border-radius: 40px;
  padding: 6px 12px;
  transition: opacity .3s, transform .3s;
  user-select: none;}

/* FIX (no-blur): strip backdrop-filter from all blurred surfaces at once.
   body.no-blur is toggled by JS blur-mode system (auto/on/off).
   Fallback: slightly more opaque backgrounds so panels remain readable. */
body.no-blur #toolbar,
body.no-blur #mode-toggle,
body.no-blur #brand-mark,
body.no-blur .wp,
body.no-blur #bm-panel,
body.no-blur #bg-panel,
body.no-blur #ft-stylebar {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Compensate opacity lost from backdrop-filter removal */
body.no-blur #toolbar,
body.no-blur #mode-toggle,
body.no-blur #brand-mark {
  background: color-mix(in srgb, var(--bg2) 92%, transparent) !important;
}

body.no-blur .wp {
  background: color-mix(in srgb, var(--bg2) 85%, transparent) !important;
}

body.no-blur #bm-panel,
body.no-blur #bg-panel {
  background: var(--bg2) !important;
}

body.no-blur #ft-stylebar {
  background: color-mix(in srgb, var(--bg2) 90%, transparent) !important;
}

/* Glass theme: keep glass feel even without blur by using a tinted bg */
body.t-glass.no-blur #toolbar,
body.t-glass.no-blur #mode-toggle,
body.t-glass.no-blur .wp {
  background: rgba(15, 20, 50, 0.88) !important;
}

body.view-mode #toolbar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(-8px);
}

.tb-sep {
  width: 1px;
  height: 18px;
  background: var(--border2);
  margin: 0 2px;
}

.tb-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  transition: all .15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tb-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

.tb-btn.active {
  background: var(--accent2);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.theme-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all .15s;
  flex-shrink: 0;
}

.theme-dot:hover {
  transform: scale(1.15);
}

.theme-dot.active {
  border-color: var(--accent);
}

.td-dark {
  background: #0d0d0f;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.td-light {
  background: #f0ece5;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.td-glass {
  background: linear-gradient(135deg, #1a1a2e, #0f3460);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.td-bw {
  background: #fff;
  box-shadow: inset 0 0 0 1px #000;
}

/* ══ MODE TOGGLE ══ */
#mode-toggle {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 200;
  background: var(--surface2);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 11px;
  font-family: var(--font-sans);
  color: var(--text2);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: .05em;
}

#mode-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent2);
}

body.view-mode #mode-toggle {
  background: var(--accent2);
  color: var(--accent);
  border-color: var(--accent);
}

/* ══ BRAND MARK ══ */
#brand-mark {
  position: fixed;
  top: 14px;
  left: 20px;
  z-index: 9999;
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid var(--border2);
  background: var(--surface2);
  backdrop-filter: blur(16px);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 30px;
  font-style: italic;
  line-height: 1;
  letter-spacing: .03em;
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.35),
    0 0 10px rgba(0, 0, 0, 0.45),
    0 0 10px rgba(255, 255, 255, 0.18);
  pointer-events: none;
  user-select: none;
}

/* ══ WIDGET PANEL ══ */
.wp {
  position: absolute;
  min-width: 160px;
  min-height: 60px;
  background: var(--surface);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  transition: border-color .2s, box-shadow .2s, background .3s;
  user-select: none;
}

body.t-glass .wp {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
}

body.t-bw .wp {
  background: #fff;
  border-color: #000;
}

.wp:hover {
  border-color: var(--border2);
}

.wp.dragging {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  border-color: var(--accent);
  opacity: .95;
  z-index: 9999 !important;
}

.wp.resizing {
  border-color: var(--accent);
  z-index: 9999 !important;
}

/* VIEW MODE */
body.view-mode .wp {
  cursor: default !important;
}

body.view-mode .wp-header {
  display: none !important;
}

body.view-mode .wp-resize {
  display: none !important;
}

body.view-mode .wp:hover {
  border-color: var(--border);
}

body.view-mode .wp[data-type="clock"],
body.view-mode .wp[data-type="bookmark"] {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

body.view-mode .wp[data-type="bookmark"] .wp-body {
  padding: 4px;
}

body.view-mode .bm-widget-favicon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

body.view-mode .bm-widget-name {
  opacity: .65;
  font-size: 10px;
}

body.view-mode .wp[data-type="clock"] .wp-body {
  padding: 0;
}

body.view-mode .wp[data-type="note"] .wp-body {
  padding: 10px 14px;
}

body.view-mode .wp[data-type="note"] .note-toolbar {
  display: none !important;
}

body.view-mode .wp[data-type="note"] .note-edit-area {
  display: none !important;
}

body.view-mode .wp[data-type="note"] .note-preview-area {
  display: block !important;
  overflow-y: auto !important;
}

body.view-mode .wp[data-type="todo"] .todo-input-row {
  display: none !important;
}

body.view-mode .wp[data-type="todo"] .todo-clear-btn {
  display: none !important;
}

body.view-mode .wp[data-type="todo"] .ti-del {
  display: none !important;
}

/* drag handle */
.wp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  cursor: grab;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.wp-header:active {
  cursor: grabbing;
}

.wp-title {
  font-size: 10px;
  font-weight: 500;
  color: var(--text3);
  letter-spacing: .12em;
  text-transform: uppercase;
}

.wp-actions {
  display: flex;
  gap: 4px;
}

.wp-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 13px;
  padding: 1px 4px;
  border-radius: 4px;
  transition: color .15s;
}

.wp-btn:hover {
  color: var(--text);
}

.wp-body {
  flex: 1;
  overflow: hidden;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wp-resize {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 4px;
  opacity: .4;
  transition: opacity .15s;
}

.wp-resize:hover,
.wp.resizing .wp-resize {
  opacity: 1;
}

/* ══ CLOCK ══ */
.wp[data-type="clock"] .wp-body {
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
  overflow: hidden;
}

body.view-mode .wp[data-type="clock"] .wp-body {
  padding: 0;
}

.clock-digital {
  font-family: var(--font-mono);
  font-weight: 300;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: font-size .2s;
}

.clock-analog {
  cursor: pointer;
  display: block;
  margin: 0 auto;
}

.clock-date {
  font-size: 11px;
  color: var(--text2);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-top: 8px;
  text-align: center;
}

body.view-mode .clock-date {
  margin-top: 6px;
}

/* ══ BOOKMARKS ══ */
.bm-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  position: relative;
  transition: border-color .15s;
  cursor: pointer;
}

.bm-item:hover {
  border-color: var(--border2);
}

.bm-del {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  border-radius: 50%;
  width: 15px;
  height: 15px;
  font-size: 9px;
  color: #fff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.bm-item:hover .bm-del {
  display: flex;
}

.bm-favicon {
  width: 13px;
  height: 13px;
  border-radius: 2px;
}

.bm-widget-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: opacity .15s;
  width: 100%;
  height: 100%;
}

.bm-widget-inner:hover {
  opacity: .8;
}

.bm-favicon-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.bm-widget-favicon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: block;
  object-fit: contain;
}

.bm-favicon-letter {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface2);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  color: var(--text2);
  border: 1px solid var(--border2);
}

.bm-widget-name {
  font-size: 11px;
  color: var(--text2);
  text-align: center;
  letter-spacing: .04em;
  word-break: break-word;
  max-width: 100px;
}

/* bookmark dropdown panel */
#bm-panel {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 16px 18px;
  width: 320px;
  display: none;
  flex-direction: column;
  gap: 12px;
  backdrop-filter: blur(30px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
}

body.t-glass #bm-panel {
  background: rgba(15, 20, 50, 0.9);
}

#bm-panel.open {
  display: flex;
}

#bm-panel-title {
  font-size: 10px;
  color: var(--text3);
  letter-spacing: .1em;
  text-transform: uppercase;
}

#bm-saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bm-saved-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all .15s;
  min-width: 64px;
  max-width: 80px;
  position: relative;
}

.bm-saved-item:hover {
  border-color: var(--border2);
  background: var(--surface2);
}

.bm-saved-item img {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}

.bm-saved-item span {
  font-size: 10px;
  color: var(--text2);
  text-align: center;
  word-break: break-word;
  line-height: 1.3;
}

.bm-saved-del {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  border-radius: 50%;
  width: 15px;
  height: 15px;
  font-size: 9px;
  color: #fff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.bm-saved-item:hover .bm-saved-del {
  display: flex;
}

#bm-add-row {
  display: flex;
  gap: 6px;
}

#bm-panel-close {
  align-self: flex-end;
  font-size: 11px;
  padding: 3px 10px;
}

/* ══ TODO ══ */
.todo-list-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  flex: 1;
}

.todo-list-wrap::-webkit-scrollbar {
  width: 3px;
}

.todo-list-wrap::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 2px;
}

.ti {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
}

.ti.done .ti-text {
  text-decoration: line-through;
  color: var(--text3);
}

.ti-chk {
  width: 15px;
  height: 15px;
  border-radius: 4px;
  border: 1.5px solid var(--border2);
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  transition: all .15s;
}

.ti-chk.on {
  background: var(--accent);
  border-color: var(--accent);
}

.ti-chk.on::after {
  content: '✓';
  font-size: 8px;
  color: var(--bg);
}

.ti-text {
  flex: 1;
  line-height: 1.45;
  word-break: break-word;
  user-select: text;
}

.ti-del {
  opacity: 0;
  font-size: 11px;
  color: var(--red);
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .15s;
  padding-top: 1px;
}

.ti:hover .ti-del {
  opacity: 1;
}

.todo-input-row {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ══ NOTE ══ */
.note-toolbar {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.note-fmt-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all .15s;
}

.note-fmt-btn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border2);
}

.note-toggle-btn {
  font-size: 10px;
  padding: 2px 8px;
  margin-left: auto;
  border-radius: 10px;
}

.note-edit-area {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  outline: none;
  user-select: text;
  min-height: 60px;
}

.note-edit-area::placeholder {
  color: var(--text3);
}

.note-preview-area {
  flex: 1;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text);
  user-select: text;
  display: none;
}

.note-preview-area::-webkit-scrollbar {
  width: 3px;
}

.note-preview-area::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 2px;
}

.note-preview-area h1,
.note-preview-area h2,
.note-preview-area h3 {
  font-family: var(--font-display);
  font-weight: 400;
  margin: 8px 0 4px;
}

.note-preview-area h1 {
  font-size: 20px;
}

.note-preview-area h2 {
  font-size: 16px;
}

.note-preview-area h3 {
  font-size: 14px;
}

.note-preview-area p {
  margin: 4px 0;
}

.note-preview-area strong {
  font-weight: 600;
}

.note-preview-area em {
  font-style: italic;
}

.note-preview-area code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 4px;
}

.note-preview-area ul,
.note-preview-area ol {
  padding-left: 18px;
  margin: 4px 0;
}

.note-preview-area li {
  margin: 2px 0;
}

.note-preview-area blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  color: var(--text2);
  margin: 6px 0;
}

.note-preview-area a {
  color: var(--accent);
  text-decoration: none;
}

.note-preview-area hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* ══ POMODORO ══ */
.pomo-time {
  font-family: var(--font-mono);
  font-size: 42px;
  font-weight: 300;
  color: var(--text);
  line-height: 1;
  text-align: center;
}

.pomo-label {
  font-size: 10px;
  color: var(--text2);
  letter-spacing: .1em;
  text-transform: uppercase;
  text-align: center;
  margin-top: 4px;
}

.pomo-track {
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 10px;
}

/* FIX: was 'transition: width 1s linear' which fights the JS 1s update interval,
   causing each new value to interrupt the previous transition and create jank.
   0.5s finishes well before the next JS update arrives. */
.pomo-bar {
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s linear;
}

.pomo-btns {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.pomo-btn {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 18px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all .15s;
}

.pomo-btn:hover {
  background: var(--accent2);
  border-color: var(--accent);
  color: var(--accent);
}

.pomo-modes {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
}

.pomo-mode {
  font-size: 10px;
  color: var(--text3);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 10px;
  transition: all .15s;
  border: 1px solid transparent;
}

.pomo-mode.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent2);
}

.pomo-sessions {
  font-size: 10px;
  color: var(--text3);
  text-align: center;
  margin-top: 6px;
}

/* ══ FREE TEXT ══ */
.ft-wrapper {
  position: absolute;
  display: inline-block;
}

.ft-note {
  display: block;
  background: transparent;
  border: none;
  outline: none;
  font-family: 'Lora', 'Georgia', 'Times New Roman', serif;
  font-size: 14px;
  color: var(--text);
  min-width: 60px;
  min-height: 22px;
  resize: none;
  overflow: hidden;
  line-height: 1.5;
  padding: 2px 4px;
  cursor: move;
}

.ft-note:focus {
  cursor: text;
  border-bottom: 1px dashed var(--border2);
}

body.view-mode .ft-note {
  cursor: default;
  pointer-events: none;
  border-bottom: none;
}

body.view-mode .ft-del-btn {
  display: none !important;
}

body.view-mode .ft-resize {
  display: none !important;
}

.ft-del-btn {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3;
}

.ft-wrapper:hover .ft-del-btn {
  display: flex;
}

.ft-resize {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 16px;
  height: 16px;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  cursor: nwse-resize;
  z-index: 3;
}

.ft-wrapper:hover .ft-resize {
  display: flex;
}

.ft-resize svg {
  display: block;
}

/* ══ INPUTS ══ */
.mini-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color .2s;
}

.mini-input:focus {
  border-color: var(--accent);
}

.mini-input::placeholder {
  color: var(--text3);
}

.add-btn {
  background: var(--accent2);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all .15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.add-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

/* ══ BG PANEL ══ */
#bg-panel {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 18px 20px;
  width: 340px;
  display: none;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(30px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
}

body.t-glass #bg-panel {
  background: rgba(15, 20, 50, 0.85);
}

#bg-panel.open {
  display: flex;
}

body.view-mode #bg-panel {
  display: none !important;
}

.bg-section-title {
  font-size: 10px;
  color: var(--text3);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.bg-tabs {
  display: flex;
  gap: 6px;
}

.bg-tab {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  color: var(--text2);
  background: transparent;
  font-family: var(--font-sans);
  transition: all .15s;
}

.bg-tab.active {
  background: var(--accent2);
  border-color: var(--accent);
  color: var(--accent);
}

#bg-solid-panel,
#bg-gradient-panel,
#bg-image-panel {
  display: none;
}

#bg-solid-panel.show,
#bg-gradient-panel.show,
#bg-image-panel.show {
  display: block;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .15s, border-color .15s;
  flex-shrink: 0;
}

.color-swatch:hover {
  transform: scale(1.12);
}

.color-swatch.active {
  border-color: var(--accent);
}

input[type=color] {
  width: 36px;
  height: 28px;
  border: 1px solid var(--border2);
  border-radius: 6px;
  cursor: pointer;
  background: none;
  padding: 1px;
}

.grad-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.grad-preset {
  width: 52px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all .15s;
}

.grad-preset:hover {
  transform: scale(1.06);
}

.grad-preset.active {
  border-color: var(--accent);
}

.img-upload-btn {
  width: 100%;
  padding: 8px;
  border: 1px dashed var(--border2);
  border-radius: 8px;
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  background: transparent;
  font-family: var(--font-sans);
  transition: all .15s;
  margin-top: 8px;
  display: block;
}

.img-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

input[type=range] {
  flex: 1;
  accent-color: var(--accent);
}

/* ══ HINT ══ */
#ft-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text2);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
  z-index: 300;
}

#ft-hint.show {
  opacity: 1;
}

/* ══ FREE TEXT STYLEBAR ══ */
#ft-stylebar {
  position: fixed;
  z-index: 410;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  backdrop-filter: blur(18px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
}

#ft-stylebar.show {
  display: flex;
}

body.view-mode #ft-stylebar {
  display: none !important;
}

.fts-btn {
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: var(--font-sans);
  cursor: pointer;
  line-height: 1.2;
  min-width: 30px;
}

.fts-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.fts-btn.active {
  background: var(--accent2);
  border-color: var(--accent);
  color: var(--accent);
}

#ft-color {
  width: 30px;
  height: 24px;
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 0;
  background: none;
  cursor: pointer;
}

#ft-size-read {
  font-size: 10px;
  color: var(--text2);
  min-width: 34px;
  text-align: center;
}

/* ══ IMAGE WARNING TOAST ══ */
#img-warn {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text);
  background: var(--red);
  border-radius: 20px;
  padding: 5px 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
  z-index: 400;
  white-space: nowrap;
}

#img-warn.show {
  opacity: 1;
}

::-webkit-scrollbar {
  width: 3px;
}

::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 2px;
}

/* ══ REDUCED MOTION SAFETY NET ══
   If the OS prefers reduced motion, remove all decorative transitions
   regardless of blur-mode setting. Blur is already handled by JS detecting
   prefers-reduced-motion as a low-spec vote, but this covers transitions too. */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}