html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #f3f4f6;
  color: #1f2937;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#page-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#root {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(520px, 920px);
  justify-content: center;
  overflow: hidden;
}

#panel {
  border-right: 1px solid #e5e7eb;
  padding: 16px;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
  --panel-font-size: 14px;
}

#panel h1 {
  margin: 0;
  font-size: 20px;
  color: #111827;
}

.desc {
  margin: 0;
  color: #374151;
  font-size: var(--panel-font-size);
  line-height: 1.5;
  font-weight: 500;
}

.desc-sub {
  margin: 4px 0 0;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.5;
}

.panel-highlights {
  margin: 8px 0 0;
  padding-left: 16px;
  font-size: 12px;
  line-height: 1.55;
  color: #6b7280;
}

.panel-highlights li {
  margin-bottom: 4px;
}

.panel-highlights li:last-child {
  margin-bottom: 0;
}

.panel-highlights strong {
  color: #4b5563;
  font-weight: 600;
}

#panel-bottom {
  flex: 1;
  min-height: 0;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.panel-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.panel-tags span {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 11px;
  line-height: 1.4;
}

.panel-diff {
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  color: #9ca3af;
}

#prompt-input {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 140px;
  font-size: var(--panel-font-size);
  line-height: 1.5;
  background: #fafafa;
  border: 1px solid #d1d5db;
  color: #111827;
  border-radius: 8px;
  padding: 10px;
  outline: none;
}

#prompt-input:focus {
  border-color: #93b4f5;
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.15);
}

.actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.btn-template {
  flex: 0 0 auto;
  min-width: 108px;
  padding: 10px 10px;
  background: #5b8def;
  color: #fff;
}

.btn-template:hover:not(:disabled) {
  background: #4a7de0;
  color: #fff;
}

.btn-generate {
  flex: 0 0 auto;
  min-width: 72px;
  padding: 10px 12px;
  background: #16a34a;
  color: #fff;
}

.btn-generate:hover:not(:disabled) {
  background: #15803d;
  color: #fff;
}

.template-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

.template-modal.hidden {
  display: none;
}

.template-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.template-modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}

.template-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
}

.template-modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #111827;
}

.template-modal-close {
  flex-shrink: 0;
}

.template-modal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 0;
}

.template-tab {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  background: #f3f4f6;
  color: #4b5563;
  border: 1px solid #d1d5db;
}

button.template-tab:hover:not(:disabled) {
  background: #e5e7eb;
  color: #374151;
}

.template-tab.active {
  background: #5b8def;
  color: #fff;
  border-color: #5b8def;
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.18);
}

button.template-tab.active:hover:not(:disabled) {
  background: #4a7de0;
  color: #fff;
}

.template-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  padding: 12px 16px 16px;
  overflow: auto;
}

.template-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  padding: 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fafafa;
  color: inherit;
  text-align: left;
  font: inherit;
  font-weight: 400;
}

button.template-card:hover:not(:disabled) {
  border-color: #93b4f5;
  background: #f8fbff;
  color: inherit;
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.12);
}

.template-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

.template-card-prompt {
  font-size: 13px;
  line-height: 1.45;
  color: #374151;
  word-break: break-word;
}

.template-card-desc {
  font-size: 12px;
  line-height: 1.45;
  color: #6b7280;
}

.template-card-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.template-card-tag[data-mode="2d"] {
  background: #dbeafe;
  color: #1d4ed8;
}

.template-card-tag[data-mode="3d"] {
  background: #dcfce7;
  color: #15803d;
}

.template-card-tag[data-mode="video"] {
  background: #fce7f3;
  color: #be185d;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: #5b8def;
  color: #fff;
  font-weight: 600;
  font-size: 12px;
  line-height: 1.5;
}

button:hover:not(:disabled) {
  background: #4a7de0;
}

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

button.secondary {
  background: #e5e7eb;
  color: #374151;
}

#status-panel {
  flex-shrink: 0;
  min-height: 48px;
  padding: 10px 12px;
  box-sizing: border-box;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: auto;
}

#status {
  font-size: var(--panel-font-size);
  line-height: 1.5;
  color: #374151;
  word-break: break-word;
}

#status-metrics {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e5e7eb;
  font-size: 12px;
  line-height: 1.6;
  color: #6b7280;
}

#status-metrics.hidden {
  display: none;
}

#metric-time,
#metric-tokens {
  word-break: break-word;
}

#usage-stats {
  flex-shrink: 0;
  font-size: 12px;
  line-height: 1.6;
  color: #6b7280;
}

#site-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  box-sizing: border-box;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  font-size: 12px;
  line-height: 1.5;
  color: #6b7280;
}

.site-footer-link {
  color: #6b7280;
  text-decoration: none;
}

.site-footer-link:hover {
  color: #374151;
  text-decoration: underline;
}

.site-footer-sep {
  color: #d1d5db;
}

.site-footer-btn {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  color: #6b7280;
  cursor: pointer;
}

.site-footer-btn:hover:not(:disabled) {
  background: transparent;
  color: #374151;
  text-decoration: underline;
}

.contact-modal-panel {
  width: min(420px, 100%);
}

.contact-modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.contact-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contact-label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
}

.contact-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.contact-value-row code {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  color: #111827;
  word-break: break-all;
}

.contact-copy-btn {
  flex-shrink: 0;
}

.contact-copy-hint {
  min-height: 18px;
  font-size: 12px;
  color: #16a34a;
}

#stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 920px;
  background: #eef0f3;
  overflow: hidden;
}

#canvas-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 260px;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  flex-shrink: 0;
}

#stage-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 18px;
  box-sizing: border-box;
  background: #eef0f3;
  overflow: hidden;
  gap: 10px;
}

#stage-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  background: #dbeafe;
  color: #1d4ed8;
}

.mode-chip[data-mode="idle"] {
  background: #f3f4f6;
  color: #4b5563;
  font-weight: 500;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 8px;
  white-space: normal;
  text-align: center;
  max-width: 100%;
}

.mode-chip[data-mode="3d"] {
  background: #dcfce7;
  color: #15803d;
}

.mode-chip[data-mode="video"] {
  background: #fce7f3;
  color: #be185d;
}

.toggle-btn[aria-pressed="true"] {
  background: #5b8def;
  color: #fff;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 12px;
}

.stage-toolbar.hidden {
  display: none;
}

.toolbar-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: #4b5563;
}

.toolbar-row-grow {
  flex: 1;
  min-width: 160px;
}

.toolbar-row input[type="range"] {
  width: 120px;
}

.toolbar-hint {
  color: #6b7280;
}

.stage-empty-hint {
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  color: #9ca3af;
  pointer-events: none;
}

.stage-empty-hint.hidden {
  display: none;
}

.canvas-empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  z-index: 0;
}

.toolbar-empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 12px;
  box-sizing: border-box;
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 10px;
}

#glcanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #ffffff;
  z-index: 1;
}

@media (max-width: 960px) {
  html,
  body {
    overflow: auto;
  }

  #page-wrap {
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  #root {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    justify-content: stretch;
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  #panel {
    border-right: 0;
    border-bottom: 1px solid #e5e7eb;
    overflow: auto;
  }

  #canvas-container {
    min-height: 220px;
  }
}
