:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --border: #2d3561;
  --gold: #c9a84c;
  --gold2: #e8c96a;
  --cream: #fdf6e3;
  --coral: #e8856a;
  --text: #e8e8f0;
  --text2: #9090b0;
  --green: #4caf7d;
  --red: #e85a5a;
  --panel-w: min(300px, 26vw);
  --right-w: min(300px, 26vw);
  --header-h: 56px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --- TOP BAR --- */
#topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
  flex-shrink: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

#topbar::-webkit-scrollbar {
  display: none;
}

#topbar .logo {
  font-family: 'Playfair Display', serif;
  font-size: 20px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: .5px;
  white-space: nowrap;
}

#topbar .logo span {
  color: var(--cream);
  font-style: italic;
}

.tb-sep {
  width: 1px;
  height: 32px;
  background: var(--border);
  margin: 0 4px;
}

.tb-btn {
  height: 32px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all .2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.tb-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.tb-btn.active {
  background: var(--gold);
  color: #1a1a2e;
  border-color: var(--gold);
  font-weight: 600;
}

.tb-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

#topbar .spacer {
  flex: 1;
}

.tb-select {
  height: 32px;
  padding: 0 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.tb-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text2);
}

.zoom-btn {
  width: 28px;
  height: 28px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- MAIN LAYOUT --- */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --- LEFT PANEL --- */
#left-panel {
  width: var(--panel-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.ptab {
  flex: 1;
  padding: 10px 4px;
  text-align: center;
  font-size: 11px;
  cursor: pointer;
  color: var(--text2);
  border-bottom: 2px solid transparent;
  transition: all .2s;
}

.ptab.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.ptab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.ptab-content.active {
  display: block;
}

/* Left panel scrollbar */
.ptab-content::-webkit-scrollbar {
  width: 4px;
}

.ptab-content::-webkit-scrollbar-track {
  background: transparent;
}

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

/* --- CANVAS AREA --- */
#canvas-wrap {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#canvas-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#canvas-wrap::-webkit-scrollbar-track {
  background: var(--bg);
}

#canvas-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

#pages-container {
  display: flex;
  flex-direction: column;
  gap: 32px;
  align-items: center;
}

.page-wrapper {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.page-num {
  color: var(--text2);
  font-size: 11px;
  width: 40px;
  text-align: right;
  padding-top: 8px;
  flex-shrink: 0;
}

.page-del {
  width: 24px;
  height: 24px;
  background: var(--red);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s;
  flex-shrink: 0;
  margin-top: 4px;
}

.page-wrapper:hover .page-del {
  opacity: 1;
}

.menu-page {
  background: #fff;
  position: relative;
  overflow: visible;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .6);
  cursor: default;
  flex-shrink: 0;
}

.menu-page.selected-page {
  outline: 2px solid var(--gold);
}

.menu-page .drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
  background: rgba(201, 168, 76, .08);
  border: 2px dashed var(--gold);
  font-size: 14px;
  color: var(--gold);
}

.menu-page.drag-over .drop-hint {
  opacity: 1;
}

/* --- PAGE HEADER/FOOTER --- */
.page-header-zone,
.page-footer-zone {
  position: absolute;
  left: 0;
  right: 0;
  min-height: 50px;
  z-index: 10;
}

.page-header-zone {
  top: 0;
}

.page-footer-zone {
  bottom: 0;
}

.zone-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  color: rgba(0, 0, 0, .2);
  pointer-events: none;
  white-space: nowrap;
}

.zone-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(0, 0, 0, .08);
}

.page-header-zone .zone-line {
  bottom: 0;
}

.page-footer-zone .zone-line {
  top: 0;
}

.page-content-area {
  position: absolute;
  left: 0;
  right: 0;
}

/* --- ELEMENTS --- */
.el {
  position: absolute;
  cursor: move;
  user-select: none;
  pointer-events: auto;
  z-index: 10;
}

.el.selected {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
  z-index: 20;
}

.el:hover:not(.selected) {
  outline: 1px dashed rgba(201, 168, 76, .5);
}

.el .resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--gold);
  border: 1px solid #fff;
  border-radius: 2px;
  display: none;
}

.el.selected .resize-handle {
  display: block;
}

.resize-handle.se {
  bottom: -4px;
  right: -4px;
  cursor: se-resize;
}

.resize-handle.sw {
  bottom: -4px;
  left: -4px;
  cursor: sw-resize;
}

.resize-handle.ne {
  top: -4px;
  right: -4px;
  cursor: ne-resize;
}

.resize-handle.nw {
  top: -4px;
  left: -4px;
  cursor: nw-resize;
}

.resize-handle.n {
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  cursor: n-resize;
}

.resize-handle.s {
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  cursor: s-resize;
}

.resize-handle.e {
  top: 50%;
  right: -4px;
  transform: translateY(-50%);
  cursor: e-resize;
}

.resize-handle.w {
  top: 50%;
  left: -4px;
  transform: translateY(-50%);
  cursor: w-resize;
}

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

.el.selected .del-btn {
  display: flex;
}

.el .rotate-handle {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 16px;
  background: var(--gold);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: grab;
  display: none;
  z-index: 20;
}

.el.selected .rotate-handle {
  display: block;
}

/* Gravy dot */
.gravy-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, .2);
  flex-shrink: 0;
}

/* --- ALIGNMENT GUIDES --- */
.align-guide {
  position: absolute;
  pointer-events: none;
  z-index: 1000;
  transition: none;
}

.align-guide-v {
  width: 1px;
  background: var(--gold);
  opacity: .8;
}

.align-guide-h {
  height: 1px;
  background: var(--gold);
  opacity: .8;
}

.align-guide-center {
  background: var(--gold);
  opacity: .4;
}

.align-guide-page {
  background: rgba(201, 168, 76, .3);
}

/* --- MARQUEE SELECTION --- */
.marquee {
  position: absolute;
  border: 1px dashed var(--gold);
  background: rgba(201, 168, 76, .1);
  pointer-events: none;
  z-index: 999;
}

.el.multi-selected {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

/* --- MULTI-SELECT ALIGN PANEL --- */
.multi-align-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  display: flex;
  gap: 4px;
  z-index: 9999;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .4);
  align-items: center;
}

.multi-align-bar .sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.multi-align-bar button {
  width: 32px;
  height: 32px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}

.multi-align-bar button:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.multi-align-bar .count {
  font-size: 11px;
  color: var(--text2);
  margin-right: 4px;
  white-space: nowrap;
}

/* --- RIGHT PANEL --- */
#right-panel {
  width: var(--right-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#right-panel::-webkit-scrollbar {
  width: 4px;
}

#right-panel::-webkit-scrollbar-track {
  background: transparent;
}

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

.rp-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
}

.rp-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 10px;
}

.rp-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  min-width: 0;
  overflow: hidden;
}

.rp-row-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  min-width: 0;
}

.rp-label {
  font-size: 10px;
  color: var(--text2);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-input {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  box-sizing: border-box;
}

.rp-input:focus {
  outline: none;
  border-color: var(--gold);
}

.rp-input[type="number"] {
  width: 100%;
  max-width: 100%;
}

.rp-color {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  padding: 2px;
  background: var(--surface2);
}

.rp-range {
  width: 100%;
  accent-color: var(--gold);
}

.rp-select {
  width: 100%;
  height: 30px;
  padding: 0 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 11px;
}

.rp-btn {
  width: 100%;
  height: 30px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: all .2s;
}

.rp-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.rp-btn-full {
  width: 100%;
  height: 32px;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  color: #1a1a2e;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all .2s;
  margin-top: 6px;
}

.rp-btn-full:hover {
  background: var(--gold2);
}

.rp-btn-full[data-page-type="cover"] {
  background: var(--coral);
  color: #1a1a2e;
}

.rp-btn-full[data-page-type="cover"]:hover {
  background: var(--coral);
  filter: brightness(1.1);
}

.rp-btn-full[data-page-type="back"] {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.rp-btn-full[data-page-type="back"]:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--gold);
}

.rp-check {
  accent-color: var(--gold);
}

.align-btns {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.align-btn {
  width: 28px;
  height: 28px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text2);
  cursor: pointer;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}

.align-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* --- GROUP-WISE PROPERTIES --- */
.rp-group {
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

.rp-group-header {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--surface);
  user-select: none;
  transition: background 0.2s;
}

.rp-group-header::-webkit-details-marker {
  display: none;
}

.rp-group-header:hover {
  background: var(--surface2);
}

.rp-group-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .8px;
}

.rp-group-arrow {
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--text2);
  border-bottom: 2px solid var(--text2);
  transform: rotate(45deg);
  transition: transform 0.2s ease-in-out;
  margin-right: 4px;
}

.rp-group[open] .rp-group-arrow {
  transform: rotate(-135deg);
}

.rp-group-content {
  padding: 12px 14px;
  background: rgba(22, 33, 62, 0.2);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rp-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  min-width: 0;
}

.rp-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.rp-field .rp-input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.rp-field-label {
  font-size: 10px;
  color: var(--text2);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rp-rot-row {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.rp-rot-row .rp-input {
  width: 70px;
  min-width: 50px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.rp-rot-row .rp-range {
  flex: 1;
  min-width: 0;
}

.rp-action-btns {
  display: flex;
  gap: 4px;
  width: 100%;
  flex-wrap: wrap;
}

.rp-action-btns .align-btn {
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
}

.rp-header-block {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

/* --- SECTION LABELS --- */
.section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin: 10px 0 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.section-label:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* --- ADD ELEMENTS PANEL --- */
.add-el-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.add-el-btn {
  padding: 10px 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.add-el-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.add-el-btn .icon {
  font-size: 20px;
}

/* --- TEMPLATES --- */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.template-card {
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all .2s;
  aspect-ratio: .7;
}

.template-card:hover {
  border-color: var(--gold);
  transform: scale(1.02);
}

.template-card canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* --- GRAVY SYSTEM --- */
.gravy-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface2);
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}

.gravy-item-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, .2);
}

.gravy-item-name {
  flex: 1;
  font-size: 12px;
}

.gravy-item-color {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 1px;
  background: none;
}

.gravy-item-del {
  width: 20px;
  height: 20px;
  background: var(--red);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.add-gravy-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.add-gravy-name {
  flex: 1;
  height: 28px;
  padding: 0 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
}

.add-gravy-color {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  padding: 2px;
  background: var(--surface2);
}

.add-gravy-btn {
  height: 28px;
  padding: 0 10px;
  background: var(--gold);
  border: none;
  border-radius: 5px;
  color: #1a1a2e;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}

/* --- PAGES PANEL --- */
.pages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.page-thumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: all .2s;
}

.page-thumb:hover {
  border-color: var(--gold);
}

.page-thumb.active {
  border-color: var(--gold);
  background: rgba(201, 168, 76, .1);
}

.page-thumb-canvas {
  width: 48px;
  height: 68px;
  background: #fff;
  border-radius: 3px;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #888;
}

.page-thumb-info {
  flex: 1;
}

.page-thumb-name {
  font-size: 12px;
  font-weight: 500;
}

.page-thumb-type {
  font-size: 10px;
  color: var(--text2);
}

.page-thumb-actions {
  display: flex;
  gap: 3px;
  align-items: center;
}

.page-thumb-move {
  width: 20px;
  height: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text2);
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.page-thumb:hover .page-thumb-move {
  display: flex;
}

.page-thumb-move:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.page-thumb-del {
  width: 20px;
  height: 20px;
  background: var(--red);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.page-thumb:hover .page-thumb-del {
  display: flex;
}

/* --- MODAL --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 {
  font-family: 'Playfair Display', serif;
  font-size: 20px;
  color: var(--gold);
  margin-bottom: 16px;
}

.modal-close {
  float: right;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 20px;
  cursor: pointer;
}

.modal.large {
  width: 640px;
}

.modal-upload-drop {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  margin-bottom: 16px;
  cursor: pointer;
}

.modal-upload-drop .preview-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.modal-upload-drop .upload-text {
  font-size: 14px;
  color: var(--text2);
}

.modal-upload-drop .upload-text span {
  font-size: 11px;
}

/* --- CONFIRM DIALOG --- */
#confirm-modal .modal {
  text-align: center;
}

#confirm-modal .modal h3 {
  color: var(--gold);
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 700;
}

#confirm-modal .modal p {
  margin: 0 auto;
}

#confirm-ok {
  transition: all .2s;
}

#confirm-ok:hover {
  background: var(--gold2);
}

#confirm-cancel:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* --- TOAST --- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gold);
  color: #1a1a2e;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  z-index: 9999;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}

/* --- LARGE SCREENS --- */
@media (min-width: 1400px) {
  :root {
    --right-w: 340px;
    --panel-w: 340px;
  }
}

/* --- CANVAS page element styles --- */
.menu-item-el {
  font-family: 'Lora', serif;
}

.shape-el {
  pointer-events: all;
}

.divider-el {
  display: flex;
  align-items: center;
}

/* --- EMPTY STATE --- */
.no-selection {
  padding: 20px;
  text-align: center;
  color: var(--text2);
  font-size: 12px;
  line-height: 1.6;
}

.no-selection .icon {
  font-size: 32px;
  margin-bottom: 8px;
}

/* --- GRADIENT EDITOR --- */
.gradient-stops {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.grad-stop {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
}

.grad-stop.active {
  border-color: var(--gold);
}

.grad-add {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px dashed var(--border);
  background: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- SCROLLBARS --- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

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

/* --- COLOR PALETTE SWATCHES --- */
.cpal-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
  max-width: 100%;
}

.cpal-swatch {
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .15s;
}

.cpal-swatch:hover {
  transform: scale(1.2);
  z-index: 2;
}

/* ================================================ */
/* RESPONSIVE -- MOBILE & TABLET                   */
/* ================================================ */

/* Hide mobile toggles on desktop */
.mob-toggle {
  display: none !important;
}

@media (max-width: 900px) {
  :root {
    --panel-w: min(280px, 70vw);
    --right-w: min(280px, 80vw);
  }

  /* -- TOPBAR (wraps to 2 lines) -- */
  #topbar {
    height: auto;
    min-height: 44px;
    padding: 6px 8px;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
  }

  .mob-toggle {
    display: flex !important;
    min-width: 36px;
    justify-content: center;
  }

  .tb-btn {
    height: 30px;
    padding: 0 8px;
    font-size: 11px;
    gap: 4px;
  }

  .tb-btn svg {
    width: 12px;
    height: 12px;
  }

  #topbar .logo {
    font-size: 16px;
  }

  .tb-sep {
    height: 24px;
    margin: 0 2px;
  }

  .tb-select {
    height: 30px;
    font-size: 11px;
    max-width: 110px;
  }

  .zoom-btn {
    width: 26px;
    height: 26px;
    font-size: 14px;
  }

  .tb-zoom {
    font-size: 11px;
  }

  /* -- MAIN LAYOUT -- */
  #main {
    position: relative;
  }

  /* -- LEFT PANEL (drawer) -- */
  #left-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    padding-top: 90px;
    width: var(--panel-w);
    z-index: 500;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: none;
  }

  #left-panel.mob-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, .5);
  }

  /* -- RIGHT PANEL (drawer) -- */
  #right-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    padding-top: 90px;
    width: var(--right-w);
    z-index: 500;
    transform: translateX(100%);
    transition: transform .25s ease;
    box-shadow: none;
  }

  #right-panel.mob-open {
    transform: translateX(0);
    box-shadow: -4px 0 24px rgba(0, 0, 0, .5);
  }

  /* -- CANVAS -- */
  #canvas-wrap {
    padding: 16px 8px;
    width: 100%;
  }

  #pages-container {
    gap: 20px;
  }

  /* -- MODALS -- */
  .modal {
    width: 95vw;
    max-width: 95vw;
    padding: 16px;
    border-radius: 10px;
  }

  .modal.large {
    width: 95vw;
  }

  .modal h3 {
    font-size: 17px;
    margin-bottom: 12px;
  }

  /* -- MULTI-ALIGN BAR -- */
  .multi-align-bar {
    bottom: 12px;
    padding: 6px 8px;
    gap: 3px;
  }

  .multi-align-bar button {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .multi-align-bar .count {
    font-size: 10px;
  }

  /* -- PROPERTIES PANEL -- */
  .rp-section {
    padding: 10px;
  }

  .rp-row {
    gap: 3px;
    margin-bottom: 8px;
  }

  .rp-row-inline {
    gap: 6px;
    margin-bottom: 8px;
  }

  .rp-label {
    font-size: 10px;
  }

  .rp-input,
  .rp-select {
    height: 28px;
    font-size: 11px;
  }

  .rp-btn-full {
    height: 30px;
    font-size: 11px;
  }

  .rp-grid-2 {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .rp-group-header {
    padding: 10px 12px;
  }

  .rp-group-content {
    padding: 10px 12px;
    gap: 8px;
  }

  .rp-rot-row .rp-input {
    width: 60px;
    min-width: 44px;
  }

  .rp-action-btns .align-btn {
    font-size: 9px;
    padding: 4px 2px;
  }

  /* -- ADD ELEMENTS GRID -- */
  .add-el-grid {
    gap: 4px;
  }

  .add-el-btn {
    padding: 8px 4px;
    font-size: 10px;
  }

  .add-el-btn .icon {
    font-size: 16px;
  }

  /* -- TEMPLATES GRID -- */
  .template-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  /* -- PAGES PANEL -- */
  .page-thumb {
    padding: 6px;
    gap: 6px;
  }

  .page-thumb-canvas {
    width: 40px;
    height: 56px;
  }

  .page-thumb-name {
    font-size: 11px;
  }

  .page-thumb-type {
    font-size: 9px;
  }
}

@media (max-width: 480px) {
  :root {
    --panel-w: 100vw;
    --right-w: 100vw;
  }

  /* -- TOPBAR (wraps, compact) -- */
  #topbar {
    height: auto;
    min-height: 40px;
    padding: 4px 6px;
    gap: 4px;
    flex-wrap: wrap;
  }

  #topbar .logo {
    font-size: 14px;
    letter-spacing: 0;
  }

  .tb-btn {
    height: 28px;
    padding: 0 6px;
    font-size: 10px;
    gap: 3px;
    border-radius: 5px;
  }

  .tb-btn svg {
    width: 11px;
    height: 11px;
  }

  .tb-sep {
    height: 20px;
    margin: 0 1px;
  }

  .tb-select {
    height: 28px;
    font-size: 10px;
    max-width: 90px;
    padding: 0 4px;
  }

  .zoom-btn {
    width: 24px;
    height: 24px;
    font-size: 13px;
  }

  /* Hide more topbar items on phone */
  .tb-zoom ~ .tb-sep,
  #page-size-sel,
  [data-action="new-design"] {
    display: none;
  }

  /* -- LEFT PANEL (full-width drawer) -- */
  #left-panel {
    width: 100vw;
    top: 0;
    padding-top: 90px;
    transition: transform .2s ease;
  }

  #left-panel.mob-open {
    transform: translateX(0);
  }

  /* -- RIGHT PANEL (full-width drawer) -- */
  #right-panel {
    width: 100vw;
    top: 0;
    padding-top: 90px;
    transition: transform .2s ease;
  }

  #right-panel.mob-open {
    transform: translateX(0);
  }

  /* -- CANVAS -- */
  #canvas-wrap {
    padding: 12px 4px;
  }

  #pages-container {
    gap: 16px;
  }

  /* -- PANEL TABS -- */
  .panel-tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .panel-tabs::-webkit-scrollbar {
    display: none;
  }

  .ptab {
    padding: 8px 8px;
    font-size: 10px;
    white-space: nowrap;
  }

  /* -- ADD ELEMENTS GRID -- */
  .add-el-grid {
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  .add-el-btn {
    padding: 6px 3px;
    font-size: 9px;
  }

  .add-el-btn .icon {
    font-size: 14px;
  }

  /* -- MODALS -- */
  .modal {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    padding: 14px;
  }

  .modal h3 {
    font-size: 15px;
    margin-bottom: 10px;
  }

  .modal p {
    font-size: 11px;
  }

  /* -- MULTI-ALIGN BAR -- */
  .multi-align-bar {
    bottom: 8px;
    left: 8px;
    right: 8px;
    transform: none;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2px;
    padding: 5px 6px;
  }

  .multi-align-bar button {
    width: 26px;
    height: 26px;
    font-size: 11px;
  }

  /* -- PROPERTIES PANEL -- */
  .rp-section {
    padding: 8px 10px;
  }

  .rp-row {
    gap: 3px;
    margin-bottom: 8px;
  }

  .rp-row-inline {
    gap: 6px;
    margin-bottom: 8px;
  }

  .rp-label {
    font-size: 10px;
  }

  .rp-grid-2 {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .rp-group-header {
    padding: 8px 10px;
  }

  .rp-group-title {
    font-size: 10px;
  }

  .rp-group-content {
    padding: 8px 10px;
    gap: 6px;
  }

  .rp-field .rp-input,
  .rp-field .rp-select {
    height: 32px;
    font-size: 13px;
  }

  .rp-rot-row .rp-input {
    width: 60px;
    min-width: 44px;
    height: 32px;
  }

  .rp-rot-row .rp-range {
    height: 24px;
  }

  .rp-action-btns .align-btn {
    min-height: 34px;
    font-size: 10px;
  }

  .align-btns {
    gap: 4px;
  }

  .align-btn {
    min-width: 28px;
    min-height: 28px;
  }

  /* -- PAGES PANEL -- */
  .page-thumb {
    padding: 5px;
    gap: 5px;
  }

  .page-thumb-canvas {
    width: 36px;
    height: 50px;
  }

  .page-thumb-name {
    font-size: 10px;
  }

  .page-thumb-type {
    font-size: 8px;
  }

  .page-thumb-actions {
    gap: 2px;
  }

  .page-thumb-move,
  .page-thumb-del {
    width: 18px;
    height: 18px;
    font-size: 9px;
  }

  /* -- GRAVY SYSTEM -- */
  .gravy-item {
    padding: 5px 6px;
    gap: 6px;
  }

  .gravy-item-dot {
    width: 16px;
    height: 16px;
  }

  .gravy-item-name {
    font-size: 11px;
  }

  .add-gravy-row {
    gap: 4px;
  }

  .add-gravy-name {
    height: 26px;
    font-size: 11px;
  }

  .add-gravy-color {
    width: 26px;
    height: 26px;
  }

  .add-gravy-btn {
    height: 26px;
    padding: 0 8px;
    font-size: 11px;
  }

  /* -- TOAST -- */
  #toast {
    bottom: 16px;
    padding: 8px 16px;
    font-size: 12px;
    max-width: 90vw;
    text-align: center;
  }
}

/* Overlay backdrop when mobile drawer is open */
@media (max-width: 900px) {
  .mob-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 499;
    display: none;
  }

  .mob-backdrop.active {
    display: block;
  }
}

@page {
  margin: 0;
}

@media print {
  html,
  body {
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: white !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #topbar,
  #left-panel,
  #right-panel {
    display: none !important;
  }

  #main {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  #canvas-wrap {
    padding: 0 !important;
    overflow: visible !important;
    height: auto !important;
    width: auto !important;
    margin: 0 !important;
  }

  #pages-container {
    gap: 0 !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .page-wrapper {
    page-break-after: always !important;
    page-break-inside: avoid !important;
    display: block !important;
    position: relative !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .page-num,
  .page-del {
    display: none !important;
  }

  .menu-page {
    box-shadow: none !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    page-break-inside: avoid !important;
    overflow: hidden !important;
  }

  .el .resize-handle,
  .el .del-btn,
  .el .rotate-handle {
    display: none !important;
  }

  .drop-hint {
    display: none !important;
  }

  #toast {
    display: none !important;
  }

  .zone-label,
  .zone-line {
    display: none !important;
  }
}

/* --- STICKERS MODAL --- */
.stickers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
}

.sticker-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  aspect-ratio: 1;
}

.sticker-item:hover {
  border-color: var(--gold);
  background: var(--surface);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sticker-item svg,
.sticker-item img {
  width: 50px;
  height: 50px;
  margin-bottom: 6px;
  pointer-events: none;
}

.sticker-item span {
  font-size: 10px;
  color: var(--text2);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* --- NOSCRIPT FALLBACK --- */
.ns-wrap {
  position: fixed;
  inset: 0;
  background: #1a1a2e;
  color: #e8e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  font-family: 'Inter', sans-serif;
}

.ns-inner {
  text-align: center;
  padding: 40px;
}

.ns-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.ns-title {
  color: #c9a84c;
  margin-bottom: 12px;
}

.ns-text {
  color: #9090b0;
  max-width: 400px;
  line-height: 1.6;
}

/* --- MOBILE TOGGLE --- */
.tb-btn-subtle {
  color: var(--text2);
  border-color: var(--border);
}

/* --- PAGES TAB --- */
.pages-actions {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gravy-tab-desc {
  font-size: 11px;
  color: var(--text2);
  margin-bottom: 10px;
  line-height: 1.5;
}

.gravy-legend-insert {
  margin-top: 16px;
}

/* --- MODAL SHARED --- */
.modal-desc {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 16px;
  line-height: 1.5;
}

.modal-desc-short {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 16px;
}

.modal-title-sub {
  margin-bottom: 8px;
}

.modal-mb-6 {
  margin-bottom: 6px;
}

.modal-mt-12 {
  margin-top: 12px;
}

.modal-mt-16 {
  margin-top: 16px;
}

/* --- TEMPLATES MODAL --- */
.modal-wide {
  width: 640px;
}

.template-filters {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.template-grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

/* --- TEMPLATE CHOICE DIALOG --- */
.modal-center {
  width: 400px;
  max-width: 90vw;
  text-align: center;
}

.tc-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.tc-msg {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 20px;
  line-height: 1.5;
}

.tc-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 10px 0;
}

.btn-gold {
  background: var(--gold);
  color: #1a1a2e;
  font-weight: 600;
  border-color: var(--gold);
}

.btn-surface {
  background: var(--surface);
  font-weight: 600;
}

.btn-surface2 {
  background: var(--surface2);
}

/* --- STICKERS MODAL --- */
.modal-medium {
  width: 480px;
  max-width: 95vw;
}

/* --- IMAGE UPLOAD --- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  margin-bottom: 16px;
  cursor: pointer;
}

.upload-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.upload-text {
  font-size: 14px;
  color: var(--text2);
}

.upload-formats {
  font-size: 11px;
}

/* --- EXPORT MODAL --- */
.modal-export {
  width: 480px;
  max-width: 90vw;
}

.export-sections {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.export-card {
  background: var(--surface2);
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.export-card-title {
  color: var(--gold);
  margin-bottom: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.export-card-desc {
  font-size: 11px;
  color: var(--text2);
  margin-bottom: 12px;
  line-height: 1.4;
}

.export-btns {
  display: flex;
  gap: 10px;
}

.export-btns-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.export-btn {
  flex: 1;
  justify-content: center;
  background: var(--surface);
  font-weight: 600;
}

.export-btn-gold {
  border-color: var(--gold);
  color: var(--gold);
}

.export-btn-muted {
  font-weight: 400;
  opacity: 0.8;
}

/* --- CONFIRM DIALOG --- */
.confirm-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

.confirm-title {
  margin-bottom: 8px;
}

.confirm-msg {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 20px;
  line-height: 1.5;
}

.confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-btn {
  flex: 1;
  justify-content: center;
}

/* ─── HIDDEN FILE INPUTS ─── */
input[type="file"].hidden-input {
  display: none;
}
