.rste-modal[hidden] {
  display: none !important;
}

.rste-modal {
  position: fixed;
  inset: 0;
  z-index: 999999;
  font-family: 'Montserrat', 'Noto Sans JP', Arial, sans-serif;
}

.rste-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 10, 20, 0.72);
  backdrop-filter: blur(3px);
}

.rste-dialog {
  position: relative;
  width: min(1520px, calc(100vw - 24px));
  height: min(96vh, 980px);
  margin: max(8px, 2vh) auto;
  border-radius: 14px;
  background: #0f172a;
  border: 1px solid #263146;
  box-shadow: 0 28px 64px rgba(0, 0, 0, 0.52);
  color: #e2e8f0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.rste-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #22314d;
  background: linear-gradient(180deg, #111f38, #0f172a);
}

.rste-header h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  color: #f8fafc;
}

.rste-header p {
  margin: 4px 0 0;
  color: #93a4bf;
  font-size: 12px;
}

.rste-close {
  appearance: none;
  border: 1px solid #334155;
  color: #e2e8f0;
  background: #172338;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}

.rste-close:hover {
  background: #1f2d46;
  border-color: #60a5fa;
  transform: translateY(-1px);
}

.rste-close:active {
  transform: translateY(0);
}

.rste-body {
  display: grid;
  grid-template-columns: 70% 30%;
  min-height: 0;
  height: 100%;
}

.rste-stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(125, 211, 252, 0.14), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(148, 163, 184, 0.16), transparent 38%),
    linear-gradient(180deg, #0b1220 0%, #0f172a 100%);
}

.rste-canvas-stage {
  width: 100%;
  height: 100%;
  min-height: 440px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid #22314d;
  background: rgba(2, 6, 23, 0.55);
  overflow: auto;
}

#rste-stage-host {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
}

#rste-stage-host canvas {
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.72);
}

.rste-sidebar {
  min-height: 0;
  overflow: auto;
  border-left: 1px solid #22314d;
  background: #0b1220;
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.rste-section {
  border: 1px solid #1e2a42;
  background: #111a2e;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.rste-section > label,
.rste-section > span {
  font-size: 11px;
  font-weight: 700;
  color: #c3d3ea;
  letter-spacing: 0.02em;
}

.rste-section input,
.rste-section select,
.rste-section textarea,
.rste-section button {
  width: 100%;
  box-sizing: border-box;
}

.rste-section input,
.rste-section select,
.rste-section textarea {
  border: 1px solid #334155;
  background: #0b1220;
  color: #e5edf9;
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
}

.rste-section input:disabled,
.rste-section select:disabled,
.rste-section textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.rste-section textarea {
  resize: vertical;
  min-height: 56px;
}

.rste-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.rste-inline.rste-align-row,
.rste-inline.rste-toggle-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rste-section button,
.rs-text-add-btn {
  appearance: none;
  border: 1px solid #3b4d6b;
  background: linear-gradient(180deg, #1e293b, #111827);
  color: #e5edf9;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.rste-section button:hover,
.rs-text-add-btn:hover {
  border-color: #60a5fa;
}

.rste-section button.is-active {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  border-color: #3b82f6;
}

.rste-magic-hint {
  font-size: 11px;
  line-height: 1.45;
  color: #cbd5e1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: rgba(15, 23, 42, 0.9);
}

#rste-stage-host.is-magic-eraser-active,
#rste-stage-host.is-magic-eraser-active canvas {
  cursor: crosshair !important;
}

#rste-save-server-btn,
#rste-ai-generate-btn,
#rste-download-btn {
  background: linear-gradient(180deg, #0f766e, #0f5c56);
  border-color: #148d82;
}

#rste-save-server-btn:hover,
#rste-ai-generate-btn:hover,
#rste-download-btn:hover {
  border-color: #34d399;
}

.rste-preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.rste-preset-grid button {
  min-height: 38px;
}

.rste-layer-list {
  display: grid;
  gap: 6px;
  max-height: 140px;
  overflow: auto;
  border: 1px solid #243352;
  border-radius: 8px;
  padding: 6px;
  background: #0b1324;
}

.rste-layer-list__empty {
  color: #9fb2cc;
  font-size: 11px;
  text-align: center;
  padding: 8px;
}

.rste-layer-list__item {
  text-align: left;
  display: grid;
  gap: 2px;
}

.rste-layer-list__item.is-active {
  border-color: #60a5fa;
  background: linear-gradient(180deg, #1e3a5f, #1d2e49);
}

.rste-layer-list__title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rste-layer-list__meta {
  color: #9fb2cc;
  font-size: 10px;
}

.rste-ai-suggestions {
  display: grid;
  gap: 6px;
}

.rste-ai-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rste-ai-item span {
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rste-ai-item strong {
  font-size: 11px;
  opacity: 0.82;
}

.rste-ai-empty {
  font-size: 11px;
  color: #93a4bf;
  text-align: center;
  padding: 8px;
  border: 1px dashed #334155;
  border-radius: 8px;
}

.rste-status {
  min-height: 18px;
  font-size: 12px;
  line-height: 1.4;
  color: #a7f3d0;
}

.rste-status.is-error {
  color: #fca5a5;
}

.rste-open {
  overflow: hidden;
}

.rs-text-add-btn {
  margin-top: 6px;
  width: auto;
}

@media (max-width: 1100px) {
  .rste-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 48vh) 1fr;
  }

  .rste-sidebar {
    border-left: 0;
    border-top: 1px solid #22314d;
  }

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

@media (max-width: 640px) {
  .rste-dialog {
    width: calc(100vw - 10px);
    height: calc(100vh - 10px);
    margin: 5px auto;
    border-radius: 10px;
  }

  .rste-header {
    padding: 10px 12px;
  }

  .rste-header h3 {
    font-size: 15px;
  }

  .rste-stage-wrap {
    padding: 8px;
  }

  .rste-sidebar {
    padding: 10px;
  }

  .rste-inline {
    grid-template-columns: 1fr;
  }

  .rste-inline.rste-align-row,
  .rste-inline.rste-toggle-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Force-hide Magic Eraser controls */
#rste-magic-eraser-btn,
#rste-magic-hint,
.rste-magic-hint {
  display: none !important;
}
