:root {
  color-scheme: light;
  --ink: #2f2942;
  --muted: #7b728b;
  --line: #eaddea;
  --line-strong: #332b45;
  --paper: #fffafd;
  --panel: rgba(255, 255, 255, 0.92);
  --pink: #ff8fc2;
  --pink-deep: #e74f99;
  --cyan: #5ecdf0;
  --mint: #66d9bd;
  --yellow: #ffd86b;
  --violet: #7c8ff7;
  --shadow: 0 16px 34px rgba(83, 58, 99, 0.14);
  --radius: 8px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 143, 194, 0.09) 1px, transparent 1px),
    linear-gradient(0deg, rgba(94, 205, 240, 0.08) 1px, transparent 1px),
    linear-gradient(135deg, #fff7fb 0%, #f5fbff 44%, #fffbea 100%);
  background-size: 28px 28px, 28px 28px, auto;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 3px solid var(--line-strong);
  background: rgba(255, 250, 253, 0.88);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 5px 5px 0 #ffd6e9;
}

.brand-name {
  font-size: 18px;
  font-weight: 900;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip-button,
.secondary-button,
.tool-button,
.primary-wide,
.primary-small,
.big-action,
.icon-button {
  min-height: 34px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.chip-button:hover,
.secondary-button:hover,
.tool-button:hover,
.primary-wide:hover,
.primary-small:hover,
.big-action:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 4px 4px 0 rgba(47, 41, 66, 0.16);
}

.chip-button:disabled,
.primary-wide:disabled,
.secondary-button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chip-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
}

.chip-button.primary,
.primary-wide,
.primary-small {
  background: linear-gradient(180deg, #ffabd0, #ff78b4);
  color: #fff;
}

.chip-button.verified {
  background: linear-gradient(180deg, #bdf4e5, #66d9bd);
  color: var(--ink);
}

.file-chip {
  user-select: none;
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 20px;
  border-radius: 6px;
  background: #fff6c8;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  font-size: 10px;
  font-weight: 900;
}

.workspace {
  flex: 1;
  width: min(100%, 1680px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 16px;
  padding: 16px;
}

.canvas-panel,
.side-panel,
.panel-block {
  min-width: 0;
}

.stage {
  position: relative;
  min-height: calc(100vh - 128px);
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, rgba(255, 216, 107, 0.22) 25%, transparent 25% 75%, rgba(255, 216, 107, 0.22) 75%),
    linear-gradient(45deg, rgba(102, 217, 189, 0.2) 25%, transparent 25% 75%, rgba(102, 217, 189, 0.2) 75%),
    #ffffff;
  background-size: 34px 34px;
  background-position: 0 0, 17px 17px, 0 0;
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
}

.stage.dragover {
  outline: 5px solid rgba(94, 205, 240, 0.45);
}

#patternCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(130px, 220px) minmax(220px, 420px);
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 28px;
}

.stage:not(.empty) .empty-state {
  display: none;
}

.empty-mascot {
  width: min(34vw, 220px);
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 10px 10px 0 rgba(94, 205, 240, 0.26);
  background: #fff;
}

.empty-card {
  display: grid;
  gap: 12px;
}

.big-action {
  height: 58px;
  padding: 0 20px;
  font-size: 17px;
  font-weight: 900;
  background: #fff;
}

.big-action:first-child {
  background: #ff8fc2;
  color: #fff;
}

.big-action.ghost {
  background: #fff;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-block {
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}

.block-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.block-title h2 {
  margin: 0;
  font-size: 15px;
}

.block-title span {
  color: var(--muted);
  font-size: 12px;
}

.control-group {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.control-group label,
.field span {
  font-size: 12px;
  font-weight: 800;
}

.range-row,
.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.number-input,
select,
.field input {
  width: 88px;
  height: 34px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 8px;
  background: #fff;
  color: var(--ink);
}

select {
  width: 100%;
}

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 54px;
  height: 30px;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle span {
  width: 54px;
  height: 30px;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: #f0e8f2;
}

.toggle span::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 4px;
  top: 4px;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  transition: transform 0.16s ease, background 0.16s ease;
}

.toggle input:checked + span {
  background: #bdf4e5;
}

.toggle input:checked + span::after {
  transform: translateX(24px);
  background: var(--mint);
}

.button-stack {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.secondary-button {
  padding: 7px 9px;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
}

.segmented,
.preset-row,
.tool-strip,
.mobile-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented {
  margin-bottom: 9px;
}

.preset-row {
  margin-bottom: 10px;
}

.segmented button,
.preset-row button {
  min-height: 30px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.segmented button.active,
.preset-row button.active,
.tool-button.active {
  background: #7c8ff7;
  color: #fff;
}

.tool-strip {
  margin-bottom: 10px;
}

.tool-button {
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
}

.mobile-tools {
  display: none;
  margin-top: 10px;
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 7px;
  max-height: 190px;
  overflow: auto;
  padding: 2px;
}

.swatch {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  display: grid;
  place-items: end center;
  overflow: hidden;
}

.swatch span {
  width: 100%;
  min-height: 16px;
  text-align: center;
  font-size: 9px;
  line-height: 16px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
}

.swatch.active {
  outline: 4px solid rgba(255, 143, 194, 0.5);
}

.swatch.excluded::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-top: 3px solid #ef4444;
  transform: rotate(-35deg);
}

.export-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
  font-size: 12px;
  color: var(--ink);
}

.export-options label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.primary-wide {
  width: 100%;
  height: 42px;
  font-weight: 900;
}

.primary-small {
  min-width: 86px;
  padding: 7px 14px;
  font-weight: 900;
}

.stats-block {
  min-height: 160px;
}

.stats-list {
  display: grid;
  gap: 6px;
  max-height: 170px;
  overflow: auto;
}

.stat-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.stat-color {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line-strong);
  border-radius: 6px;
}

.bottom-tabbar {
  display: none;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(47, 41, 66, 0.42);
  backdrop-filter: blur(3px);
}

.modal-card {
  width: min(92vw, 420px);
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fffafd;
  box-shadow: 14px 14px 0 rgba(47, 41, 66, 0.18);
  padding: 16px;
}

.wide-modal .modal-card {
  width: min(92vw, 720px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
}

.icon-button {
  width: 34px;
  height: 34px;
  font-weight: 900;
  background: #fff;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field input {
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.history-card {
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.history-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #f6f2f7;
}

.history-card .history-body {
  padding: 9px;
  display: grid;
  gap: 8px;
  font-size: 12px;
}

.history-actions {
  display: flex;
  gap: 6px;
}

.history-actions button {
  flex: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(47, 41, 66, 0.9);
  color: #fff;
  padding: 9px 16px;
  font-size: 13px;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.auth-card {
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 143, 194, 0.12) 1px, transparent 1px),
    linear-gradient(0deg, rgba(94, 205, 240, 0.12) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(180deg, #000, transparent 68%);
}

.auth-card > * {
  position: relative;
}

.auth-hero {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  padding: 10px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
}

.auth-hero img {
  width: 58px;
  height: 58px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff7fb;
}

.auth-hero strong,
.auth-hero span {
  display: block;
}

.auth-hero strong {
  font-size: 16px;
}

.auth-hero span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  margin-top: 12px;
}

.get-card-modal {
  text-align: center;
}

.get-card-modal .modal-head {
  text-align: left;
}

.get-card-image {
  display: block;
  width: min(100%, 320px);
  max-height: 56vh;
  object-fit: contain;
  margin: 12px auto;
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
}

.admin-page {
  min-height: 100vh;
}

.admin-page.is-locked {
  overflow: hidden;
}

.admin-page.is-locked .admin-shell {
  filter: blur(5px);
  pointer-events: none;
  user-select: none;
}

.page-lock {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(255, 143, 194, 0.12) 1px, transparent 1px),
    linear-gradient(0deg, rgba(94, 205, 240, 0.12) 1px, transparent 1px),
    rgba(255, 250, 253, 0.84);
  background-size: 26px 26px;
  backdrop-filter: blur(8px);
}

.page-lock[hidden] {
  display: none;
}

.page-lock-card {
  width: min(92vw, 380px);
  display: grid;
  gap: 12px;
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fffafd;
  box-shadow: 14px 14px 0 rgba(47, 41, 66, 0.2);
  padding: 18px;
  text-align: center;
}

.page-lock-mascot {
  width: 86px;
  height: 86px;
  justify-self: center;
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 6px 6px 0 rgba(94, 205, 240, 0.25);
}

.page-lock-title {
  font-size: 20px;
  font-weight: 900;
}

.page-lock-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.page-lock-card .field {
  text-align: left;
  margin-bottom: 0;
}

.admin-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.admin-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px;
  border: 3px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 250, 253, 0.92);
  box-shadow: var(--shadow);
}

.admin-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(280px, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.admin-card {
  min-height: 100%;
}

.admin-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.admin-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.code-box {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
  color: var(--ink);
  font: 800 14px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.admin-list-head {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 420px);
  gap: 12px;
  align-items: start;
}

.admin-search {
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 8px;
}

.admin-search input,
.admin-card input {
  width: 100%;
  height: 36px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0 9px;
  background: #fff;
  color: var(--ink);
}

.admin-table-wrap {
  overflow: auto;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
  font-size: 12px;
}

.admin-table th,
.admin-table td {
  padding: 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff1f8;
  color: var(--ink);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  font-weight: 900;
  white-space: nowrap;
}

.status-pill.ok {
  background: #c9f8e9;
}

.status-pill.off {
  background: #f0e8f2;
}

.table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.secondary-button.danger {
  background: #fff0f2;
  color: #b4233c;
}

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

  .stage {
    min-height: 62vh;
  }

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

  .stats-block {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: 58px;
  }

  .topbar {
    align-items: flex-start;
    padding: 10px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand-name {
    font-size: 15px;
  }

  .brand-subtitle {
    font-size: 11px;
  }

  .top-actions {
    gap: 6px;
  }

  .chip-button span:not(.icon) {
    display: none;
  }

  .workspace {
    padding: 10px;
    gap: 10px;
  }

  .stage {
    min-height: 56vh;
    touch-action: pan-y;
  }

  #patternCanvas {
    touch-action: pan-y;
  }

  .empty-state {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .empty-mascot {
    width: 136px;
    justify-self: center;
  }

  .big-action {
    height: 48px;
    font-size: 15px;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .panel-block {
    padding: 12px;
    scroll-margin-bottom: 78px;
  }

  .button-stack {
    grid-template-columns: 1fr;
  }

  .segmented,
  .preset-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 2px 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .segmented::-webkit-scrollbar,
  .preset-row::-webkit-scrollbar,
  .swatch-grid::-webkit-scrollbar {
    display: none;
  }

  .segmented button,
  .preset-row button {
    flex: 0 0 auto;
    min-width: 76px;
    min-height: 42px;
    padding: 6px 12px;
    font-size: 14px;
  }

  .swatch-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 64px;
    grid-template-columns: none;
    grid-template-rows: repeat(2, 60px);
    gap: 12px;
    height: 144px;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 4px 12px;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .swatch {
    width: 64px;
    height: 60px;
    min-width: 64px;
    min-height: 60px;
    aspect-ratio: auto;
    touch-action: manipulation;
  }

  .swatch span {
    min-height: 20px;
    font-size: 10px;
    line-height: 20px;
    white-space: nowrap;
  }

  .export-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 18px;
    font-size: 15px;
  }

  .export-options label {
    min-height: 38px;
  }

  .primary-wide {
    height: 50px;
    font-size: 16px;
  }

  .tool-strip {
    display: none;
  }

  .mobile-tools {
    display: flex;
  }

  .bottom-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    border-top: 3px solid var(--line-strong);
    background: rgba(255, 250, 253, 0.94);
    backdrop-filter: blur(10px);
  }

  .bottom-tabbar button {
    height: 38px;
    border: 2px solid var(--line-strong);
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    font-weight: 900;
  }

  .modal-card {
    width: min(94vw, 420px);
    padding: 14px;
  }

  .auth-actions {
    grid-template-columns: 1fr;
  }

  .get-card-image {
    max-height: 50vh;
  }

  .admin-shell {
    padding: 10px;
  }

  .admin-hero,
  .admin-list-head {
    grid-template-columns: 1fr;
  }

  .admin-hero {
    align-items: stretch;
  }

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

  .admin-two,
  .admin-search {
    grid-template-columns: 1fr;
  }

  .admin-link {
    justify-content: center;
  }
}
