:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --line-soft: #e8e8ed;
  --surface: rgba(255, 255, 255, 0.82);
  --raised: #f5f5f7;
  --primary: #0071e3;
  --primary-dark: #005bb5;
  --danger: #b00020;
  --radius: 18px;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue",
    Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.canvas-login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 25%, rgba(0, 113, 227, 0.16), transparent 34%),
    linear-gradient(#ffffff 0 55%, #f5f5f7 55% 100%);
}

.login-card {
  display: grid;
  gap: 18px;
  width: min(480px, 100%);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  padding: 36px;
  text-align: center;
}

.login-card p,
.composer > div p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-card h1,
.composer h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 52px);
  line-height: 1;
}

.login-card label,
.composer label {
  display: grid;
  gap: 8px;
  text-align: left;
}

.login-card label span,
.composer label span {
  color: #424245;
  font-size: 13px;
  font-weight: 700;
}

.login-card input,
.composer textarea,
.composer select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(245, 245, 247, 0.94);
  color: var(--ink);
  outline: none;
}

.login-card input,
.composer select {
  min-height: 46px;
  padding: 0 13px;
}

.composer textarea {
  min-height: 170px;
  padding: 14px;
  resize: vertical;
  line-height: 1.5;
}

.login-card input:focus,
.composer textarea:focus,
.composer select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.14);
  background: #ffffff;
}

.login-card button,
.generate-button {
  min-height: 50px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.login-card button:hover,
.generate-button:hover {
  background: var(--primary-dark);
}

.login-card strong {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.canvas-app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 72% 18%, rgba(0, 113, 227, 0.11), transparent 26%),
    radial-gradient(circle at 28% 78%, rgba(52, 199, 89, 0.1), transparent 28%),
    #f5f5f7;
}

.canvas-nav {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 22px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(251, 251, 253, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
}

.brand,
.canvas-nav a,
.canvas-nav button {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.canvas-nav nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.canvas-nav button {
  min-width: 32px;
  min-height: 30px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
}

#zoomText {
  min-width: 42px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.composer {
  position: fixed;
  top: 72px;
  left: 22px;
  z-index: 10;
  display: grid;
  gap: 18px;
  width: min(360px, calc(100vw - 44px));
  border: 1px solid rgba(210, 210, 215, 0.7);
  border-radius: 22px;
  background: var(--surface);
  padding: 22px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(28px);
}

.edit-panel {
  position: fixed;
  top: 72px;
  right: 22px;
  z-index: 14;
  display: grid;
  gap: 14px;
  width: min(420px, calc(100vw - 44px));
  max-height: calc(100vh - 96px);
  overflow: auto;
  border: 1px solid rgba(210, 210, 215, 0.72);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.88);
  padding: 18px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(28px);
}

.composer h1 {
  font-size: 30px;
}

.edit-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.edit-heading p,
.edit-heading h2,
.edit-hint {
  margin: 0;
}

.edit-heading p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.edit-heading h2 {
  font-size: 28px;
  line-height: 1.05;
}

.round-button,
.secondary-action {
  border: 1px solid var(--line-soft);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.round-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.edit-hint {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
}

.edit-panel label {
  display: grid;
  gap: 8px;
}

.edit-panel label span {
  color: #424245;
  font-size: 13px;
  font-weight: 700;
}

.edit-panel textarea {
  width: 100%;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(245, 245, 247, 0.94);
  color: var(--ink);
  outline: none;
  padding: 13px;
  resize: vertical;
  line-height: 1.5;
}

.edit-panel textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.14);
  background: #ffffff;
}

.mask-editor {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  background: #f5f5f7;
  touch-action: none;
}

.mask-editor img,
.mask-editor canvas {
  display: block;
  width: 100%;
}

.mask-editor img {
  max-height: 390px;
  object-fit: contain;
}

.mask-editor canvas {
  position: absolute;
  inset: 0;
  height: 100%;
  cursor: crosshair;
}

.brush-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.brush-row input {
  width: 100%;
}

.secondary-action {
  min-height: 38px;
  border-radius: 999px;
  padding: 0 13px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.composer-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
}

.canvas-viewport {
  position: absolute;
  inset: 48px 0 0;
  overflow: hidden;
  cursor: grab;
  background:
    linear-gradient(rgba(29, 29, 31, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 29, 31, 0.045) 1px, transparent 1px);
  background-size: 80px 80px;
}

.canvas-viewport.dragging {
  cursor: grabbing;
}

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 9000px;
  height: 7000px;
  transform-origin: 0 0;
  will-change: transform;
}

.canvas-empty {
  position: absolute;
  left: 1040px;
  top: 560px;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: 360px;
  border: 1px solid rgba(210, 210, 215, 0.72);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.78);
  padding: 28px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.08);
}

.canvas-empty span {
  width: 88px;
  height: 88px;
  border-radius: 28px;
  background:
    radial-gradient(circle at 70% 25%, #0071e3 0 8px, transparent 9px),
    linear-gradient(135deg, transparent 0 50%, rgba(52, 199, 89, 0.35) 51% 100%),
    linear-gradient(145deg, rgba(0, 113, 227, 0.16), rgba(255, 255, 255, 0.92));
}

.canvas-empty h2,
.canvas-empty p {
  margin: 0;
}

.canvas-empty p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.canvas-node {
  position: absolute;
  width: 360px;
  border: 1px solid rgba(210, 210, 215, 0.78);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  user-select: none;
}

.canvas-node.dragging {
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.18);
}

.node-preview {
  display: grid;
  place-items: center;
  min-height: 260px;
  background:
    radial-gradient(circle at center, rgba(0, 113, 227, 0.1), transparent 45%),
    #f5f5f7;
}

.node-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: contain;
}

.node-loader {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.countdown-ring {
  display: grid;
  place-items: center;
  width: 94px;
  height: 94px;
  border-radius: 50%;
  background:
    radial-gradient(circle, #ffffff 0 58%, transparent 59%),
    conic-gradient(var(--primary) var(--progress), rgba(210, 210, 215, 0.7) 0);
  color: var(--ink);
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.node-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.node-body strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-body small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.node-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.node-actions a,
.node-actions button {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--primary);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.node-actions button {
  color: var(--ink);
}

.node-actions button[data-edit-node] {
  color: var(--primary);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 44px));
  border-radius: 14px;
  background: rgba(29, 29, 31, 0.92);
  color: #ffffff;
  padding: 13px 15px;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 820px) {
  .canvas-nav {
    padding: 0 14px;
  }

  .canvas-nav nav {
    gap: 9px;
  }

  .canvas-nav nav a[href="/"],
  #zoomText {
    display: none;
  }

  .composer {
    top: 62px;
    left: 14px;
    right: 14px;
    width: auto;
    padding: 18px;
  }

  .edit-panel {
    top: auto;
    right: 14px;
    bottom: 14px;
    left: 14px;
    width: auto;
    max-height: min(72vh, 680px);
  }

  .mask-editor img {
    max-height: 260px;
  }

  .composer textarea {
    min-height: 112px;
  }

  .canvas-viewport {
    top: 48px;
  }
}
