:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --line: #dbe3ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0b1736;
  --primary-2: #1d4ed8;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Poppins", "Segoe UI", Tahoma, sans-serif;
}

body.modal-open {
  overflow: hidden;
}

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.gate-card {
  width: min(96vw, 420px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  padding: 1.25rem;
  text-align: center;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  margin: 0 auto .75rem auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.app {
  min-height: 100vh;
  padding: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.topbar p {
  margin: .25rem 0 0 0;
  color: var(--muted);
  font-size: .92rem;
}

.topbar-actions {
  display: flex;
  gap: .5rem;
}

.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  padding: .85rem;
}

.setup-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

.setup-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.field label {
  font-size: .8rem;
  color: var(--muted);
  font-weight: 600;
}

input,
select,
textarea,
button {
  font: inherit;
}

input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
}

input[type="color"].color-chip {
  width: 56px;
  min-width: 56px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid #cfd9e8;
  padding: 2px;
  -webkit-appearance: none;
  appearance: none;
}

input[type="color"].color-chip::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 8px;
}

input[type="color"].color-chip::-webkit-color-swatch {
  border: none;
  border-radius: 8px;
}

input[type="color"].color-chip::-moz-color-swatch {
  border: none;
  border-radius: 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfd9e8;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: .55rem .7rem;
}

textarea {
  resize: vertical;
  min-height: 88px;
}

.btn {
  border: 1px solid #cfd9e8;
  border-radius: 12px;
  padding: .55rem .9rem;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
}

.btn:hover {
  background: #f8fafc;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: #111f45;
}

.btn-mini {
  padding: .4rem .65rem;
  border-radius: 10px;
  font-size: .82rem;
}

.btn:disabled {
  opacity: .65;
  cursor: not-allowed;
}

.editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) minmax(340px, 1fr);
  gap: .9rem;
}

.editor-main,
.editor-side {
  min-width: 0;
}

.editor-side {
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

@supports (height: 100dvh) {
  .editor-side {
    max-height: calc(100dvh - 120px);
  }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: wrap;
}

.align-group {
  gap: .3rem;
}

.btn.btn-icon {
  min-width: 36px;
  padding: .45rem .55rem;
}

.btn-check {
  position: relative;
  user-select: none;
}

.btn-check input[type="checkbox"] {
  margin-right: .35rem;
}

.btn-check.is-active {
  border-color: #7ea6ff;
  background: #e7f0ff;
}

.btn-check span {
  font-weight: 600;
}

.shape-menu-wrap {
  position: relative;
}

.icon-menu-wrap {
  position: relative;
}

.shape-menu {
  position: absolute;
  top: calc(100% + .3rem);
  left: 0;
  min-width: 200px;
  border: 1px solid #cfd9e8;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 12px 20px rgba(15, 23, 42, .14);
  padding: .3rem;
  z-index: 40;
}

.icon-menu {
  position: absolute;
  top: calc(100% + .3rem);
  left: 0;
  width: min(520px, 92vw);
  border: 1px solid #cfd9e8;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 12px 20px rgba(15, 23, 42, .14);
  padding: .5rem;
  z-index: 50;
  display: grid;
  gap: .45rem;
}

.icon-menu input[type="search"] {
  width: 100%;
}

.icon-grid {
  max-height: 280px;
  overflow: auto;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  padding: .35rem;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: .35rem;
  background: #f8fafc;
}

.icon-item {
  border: 1px solid #d4deec;
  border-radius: 10px;
  background: #fff;
  padding: .35rem;
  display: grid;
  gap: .25rem;
  justify-items: center;
  cursor: pointer;
}

.icon-item:hover {
  border-color: #8cb1ff;
  background: #edf4ff;
}

.icon-item.is-selected {
  border-color: #2563eb;
  background: #dbeafe;
  box-shadow: inset 0 0 0 1px #2563eb;
}

.icon-item img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.icon-item span {
  max-width: 100%;
  font-size: .68rem;
  color: #475569;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(15, 23, 42, .46);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.icon-modal {
  width: min(1200px, 96vw);
  max-height: min(92vh, 920px);
  border: 1px solid #cfd9e8;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 24px 50px rgba(15, 23, 42, .28);
  padding: .85rem;
  display: grid;
  gap: .55rem;
}

.icon-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .7rem;
}

.icon-modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.icon-modal-meta {
  margin: .2rem 0 0 0;
  font-size: .8rem;
  color: var(--muted);
}

.icon-modal-search {
  display: grid;
  gap: .35rem;
}

.icon-modal-selection {
  font-size: .8rem;
  color: #475569;
}

.icon-grid.icon-grid-modal {
  max-height: calc(min(92vh, 920px) - 240px);
  min-height: 300px;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: .45rem;
  padding: .5rem;
  background: #f8fbff;
}

.icon-grid.icon-grid-modal .icon-item {
  min-height: 88px;
  padding: .45rem .35rem;
}

.icon-grid.icon-grid-modal .icon-item img {
  width: 30px;
  height: 30px;
}

.icon-grid.icon-grid-modal .icon-item span {
  font-size: .72rem;
}

.icon-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .45rem;
}

.shape-menu-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #fff;
  padding: .45rem .55rem;
  text-align: left;
  cursor: pointer;
}

.shape-menu-item:hover {
  border-color: #d7e3f4;
  background: #f8fbff;
}

.stage-wrap {
  margin-top: .75rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #eef3fa;
  padding: .5rem;
}

.preview {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 10px;
  background: #f8fafc;
  touch-action: none;
  user-select: none;
}

.stage-hint {
  margin-top: .5rem;
  font-size: .76rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.layers-list {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  max-height: 180px;
  overflow: auto;
}

.layer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .45rem;
  padding: .35rem;
  border: 1px solid transparent;
  border-radius: 10px;
  margin: .25rem;
}

.layer-row:hover {
  border-color: #c5d2e7;
  background: #f1f5fb;
}

.layer-row.active {
  border-color: #8cb1ff;
  background: #deebff;
}

.layer-actions {
  display: inline-flex;
  gap: .2rem;
}

.layer-mini-btn {
  border: 1px solid #cfd9e8;
  border-radius: 8px;
  padding: .2rem .4rem;
  background: #fff;
  cursor: pointer;
}

.layer-mini-btn:hover {
  background: #f8fafc;
}

.muted {
  font-size: .8rem;
  color: var(--muted);
  padding: .35rem .2rem;
}

.field-check label {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  font-weight: 500;
}

.text-selection-tools {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}

.text-selection-hint {
  padding-top: 0;
}

.crop-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .5rem;
}

.field-tight {
  gap: .2rem;
}

.field-tight label {
  font-size: .74rem;
}

.crop-tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}

.inspector {
  margin-top: .7rem;
}

.inspector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem;
}

.field-span-2 {
  grid-column: 1 / -1;
}

.side-actions {
  margin-top: .8rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: flex-end;
  position: sticky;
  bottom: -.85rem;
  background: linear-gradient(to top, #ffffff 72%, rgba(255, 255, 255, 0));
  padding-top: .7rem;
  padding-bottom: .25rem;
}

.toasts {
  position: fixed;
  right: .8rem;
  bottom: .8rem;
  z-index: 999;
  display: grid;
  gap: .45rem;
}

.toast {
  min-width: 240px;
  max-width: min(88vw, 360px);
  border-radius: 12px;
  border: 1px solid #b7d0ff;
  background: #eff6ff;
  color: #0f172a;
  padding: .55rem .7rem;
  box-shadow: 0 8px 18px rgba(15, 23, 42, .12);
}

.toast.error {
  border-color: #fecaca;
  background: #fef2f2;
}

@media (max-width: 1100px) {
  .editor-shell {
    grid-template-columns: 1fr;
  }

  .editor-side {
    max-height: none;
    overflow: visible;
    scrollbar-gutter: auto;
  }

  .side-actions {
    position: static;
    background: transparent;
    padding: 0;
  }
}

@media (max-width: 720px) {
  .setup-card {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .inspector-grid {
    grid-template-columns: 1fr;
  }

  .crop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .icon-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .icon-grid.icon-grid-modal {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 220px;
  }
}
