:root {
  color-scheme: light;
  --bg: #f5f0e5;
  --panel: #fffaf1;
  --ink: #1f1d1a;
  --muted: #6e655a;
  --line: #d8cfbf;
  --accent: #2b6f6a;
  --accent-strong: #184744;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  background:
    radial-gradient(circle at top, rgba(43, 111, 106, 0.12), transparent 40%),
    linear-gradient(180deg, #f7f2e7 0%, var(--bg) 100%);
  color: var(--ink);
}

.site-nav {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.92);
}

.site-nav-inner {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  max-width: 1480px;
  min-height: 58px;
  margin: 0 auto;
  padding: 0 24px;
}

.site-nav-inner a {
  color: var(--ink);
  text-decoration: none;
}

.site-nav-inner a {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--accent-strong);
  font-weight: 700;
}

.site-nav-inner a:hover {
  background: rgba(43, 111, 106, 0.1);
}

.nav-logout {
  margin-left: auto;
}

.nav-logout-button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
}

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1200;
  display: grid;
  gap: 8px;
}

.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #1f6a43;
  background: #e6f8ef;
  color: #12442b;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-size: 0.88rem;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-error {
  border-color: #8d2a1f;
  background: #fdecea;
  color: #6a1e15;
}

.toast.is-hiding {
  opacity: 0;
  transform: translateY(8px);
}

.shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.text2model-shell {
  max-width: 1680px;
}

.hero {
  padding: 8px 0 12px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0 0 12px;
  line-height: 1.05;
}

h1 {
  font-size: clamp(2.5rem, 8vw, 5rem);
}

p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.4;
}

.grid {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.preview-workspace {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
}

.preview-workspace > .panel {
  grid-column: span 6;
}

.preview-primary {
  grid-column: span 8;
  grid-row: span 2;
  padding: 12px;
}

.preview-primary .viewer-canvas {
  min-height: 760px;
  height: min(84vh, 1040px);
}

.compact-panel {
  padding: 10px;
  border-radius: 12px;
}

.compact-panel h2 {
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.controls-panel {
  grid-column: span 4;
}

.notes-panel {
  grid-column: span 4;
  border-left: 0;
  border-top: 3px solid var(--accent);
}

.metadata-panel {
  grid-column: span 4;
}

.regions-panel {
  grid-column: span 4;
}

.stack {
  display: grid;
  gap: 12px;
}

.panel {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(49, 41, 28, 0.06);
}

.status {
  border-left: 3px solid var(--accent);
}

.error {
  border-left: 3px solid #b34534;
}

.code {
  padding: 2px 5px;
  font-family: "SFMono-Regular", "SF Mono", Consolas, monospace;
  background: #efe7d7;
  border-radius: 4px;
  color: var(--ink);
  font-size: 0.85rem;
}

ul {
  padding-left: 18px;
  color: var(--muted);
  margin: 0;
}

.upload-form {
  display: grid;
  gap: 12px;
}

.dropzone {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(43, 111, 106, 0.08);
}

.dropzone.is-invalid {
  border-color: #b34534;
  background: rgba(179, 69, 52, 0.08);
}

.dropzone strong {
  font-size: 1.05rem;
  color: var(--ink);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--accent-strong);
  border-radius: 999px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
  text-decoration: none;
}

.file-button input {
  display: none;
}

.button.secondary {
  background: transparent;
  color: var(--accent-strong);
}

.meta {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.meta strong {
  color: var(--ink);
}

.json-block {
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: 12px;
  background: #efe7d7;
  color: var(--ink);
  font-family: "SFMono-Regular", "SF Mono", Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.4;
}

.viewer-shell {
  display: grid;
  gap: 10px;
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.viewer-tool {
  min-height: 32px;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 4px;
  color: var(--ink);
  font-size: 0.88rem;
}

.toggle-pill input[type="checkbox"] {
  margin: 0;
}


.viewer-canvas {
  position: relative;
  width: 100%;
  min-height: 420px;
  height: min(58vh, 560px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    radial-gradient(circle at 35% 20%, rgba(43, 111, 106, 0.12), transparent 28%),
    #faf5eb;
  touch-action: none;
}

.viewer-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewer-error {
  display: grid;
  place-items: center;
  min-height: inherit;
  height: 100%;
  padding: 20px;
  color: #a53d2f;
  font-weight: 700;
  text-align: center;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
}

.hint.is-error {
  color: #a53d2f;
  font-weight: 700;
}

.is-hidden {
  display: none !important;
}

.region-list {
  display: grid;
  gap: 8px;
}

.region-group {
  display: grid;
  gap: 8px;
}

.region-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.95rem;
}

.color-chip {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(31, 29, 26, 0.2);
  border-radius: 999px;
  background: #d8cfbf;
}

.region-button {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
  font-size: 0.92rem;
}

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

.region-button.is-active {
  border-color: var(--accent-strong);
  background: rgba(43, 111, 106, 0.08);
}

.region-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.region-detail {
  min-height: 1.4em;
  color: var(--accent-strong);
  font-weight: 700;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.compact-form {
  grid-template-columns: 1fr;
  gap: 10px;
}

.compact-form .actions,
.compact-form .error-list,
.compact-form .success-box,
.compact-form .warning-box,
.compact-form .hint,
.compact-form .meta {
  grid-column: 1 / -1;
}

.param-group {
  margin: 0;
  padding: 6px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
}

.param-group legend {
  padding: 0 6px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.group-grid {
  display: grid;
  gap: 12px 10px;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

.group-grid .field-wide {
  grid-column: 1 / -1;
}

.text-blocks {
  display: grid;
  gap: 8px;
  padding-top: 4px;
}

.text-blocks-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.text-blocks-head strong {
  font-size: 0.88rem;
}

.text-block-add {
  min-height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 0.78rem;
}

.text-block-list {
  display: grid;
  gap: 6px;
}

.text-block-card {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.text-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.text-block-header strong {
  font-size: 0.82rem;
  color: var(--accent-strong);
}

.text-block-remove {
  min-height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 0.75rem;
}

.field {
  display: grid;
  gap: 4px;
}

.field span {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 26px;
  padding: 2px 6px;
  border: 1px solid #b8af9f;
  border-radius: 4px;
  background: white;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  box-sizing: border-box;
}

.field select {
  padding-right: 2px; /* Less padding needed if using default appearance */
}

.field input[type="number"] {
  width: 100%; /* Fill the grid cell, but columns are now narrower */
  max-width: 80px;
}

/* Always show spin buttons */
.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
}

.field textarea {
  min-height: 48px;
  resize: vertical;
}

textarea[name="text"] {
  min-height: 100px !important;
  font-size: 0.95rem !important;
  border-color: var(--accent) !important;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.05);
}

.field small {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.2;
}

.radio-row {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 26px;
}

.radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.88rem;
  line-height: 1;
}

.radio-row input[type="radio"] {
  margin: 0;
  padding: 0;
  vertical-align: middle;
}


.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, rgba(43, 111, 106, 0.15), transparent 60%), #f5f0e5;
}

.login-shell {
  width: 100%;
  max-width: 400px;
}

.login-card {
  padding: 32px;
  box-shadow: 0 20px 50px rgba(49, 41, 28, 0.12);
  border-radius: 24px;
}

.login-card h1 {
  margin-bottom: 8px;
  text-align: center;
  font-size: 2rem;
}

.login-card .hint {
  text-align: center;
  margin-bottom: 24px;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form .field {
  display: grid;
  gap: 6px;
}

.login-form .field span {
  font-size: 0.8rem;
  color: var(--muted);
}

.login-form input {
  min-height: 42px;
  padding: 8px 12px;
  font-size: 1rem;
}

.login-form .button {
  width: 100%;
  margin-top: 8px;
}

.error-text {
  padding: 10px;
  margin-bottom: 16px;
  border-radius: 8px;
  background: rgba(179, 69, 52, 0.1);
  color: #b34534;
  font-size: 0.9rem;
  text-align: center;
}

.hero .text-blocks-head {
  align-items: flex-end;
}

.button.destructive {
  background: #b34534;
  border-color: #8a3225;
  color: white;
  font-weight: 700;
}

.button.destructive:hover {
  background: #d44c38;
}

.live-preview-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.custom-modal {
  width: min(480px, calc(100vw - 32px));
  border: 0;
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 25px 60px rgba(0,0,0,0.25);
  background: var(--panel);
}

.custom-modal::backdrop {
  background: rgba(31, 29, 26, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  padding: 24px;
  display: grid;
  gap: 16px;
}

.modal-header {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-body {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.modal-input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

.keychain-top-row {
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)) !important;
}

.ring-params-row {
  grid-template-columns: repeat(3, 1fr) !important;
}

.compact-corner-grid {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(4, 75px);
  margin-top: 4px;
}

.searchable-select {
  padding-right: 20px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e655a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 10px;
}

.field-error-message {
  color: #b34534;
  font-size: 0.8rem;
  line-height: 1.25;
}

.text-model-preview-panel {
  grid-column: 1 / -1;
  position: relative;
}

.preview-tools {
  display: flex;
  gap: 8px;
}

.preview-tools-corner {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
}

.viewer-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  text-decoration: underline;
}

.text-model-preview {
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 0;
  height: auto;
  max-height: min(86vh, 1260px);
  cursor: grab;
}

.text-model-preview:active {
  cursor: grabbing;
}

.model-ruler {
  position: absolute;
  z-index: 2;
  padding: 4px 8px;
  border: 1px solid rgba(31, 29, 26, 0.2);
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.82);
  color: var(--accent-strong);
  font-family: "SFMono-Regular", "SF Mono", Consolas, monospace;
  font-size: 0.82rem;
  pointer-events: none;
}

.model-ruler-x {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
}

.model-ruler-y {
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
}

.model-ruler-z {
  right: 16px;
  bottom: 16px;
}

.model-ruler-plate {
  left: 16px;
  bottom: 16px;
}

.model-preview-size {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  .shell {
    padding: 32px 14px 48px;
  }

  .preview-workspace {
    grid-template-columns: 1fr;
  }

  .preview-workspace > .panel,
  .controls-panel,
  .notes-panel,
  .metadata-panel,
  .regions-panel {
    grid-column: 1 / -1;
  }

  .preview-primary .viewer-canvas {
    min-height: 520px;
    height: 70vh;
  }

  .text-model-preview-panel {
    grid-column: 1 / -1;
  }

  .text-model-preview {
    max-height: none;
  }
}

.error-list {
  display: grid;
  gap: 8px;
  color: #a53d2f;
}

.success-box {
  padding: 14px 16px;
  border: 1px solid rgba(43, 111, 106, 0.3);
  border-radius: 14px;
  background: rgba(43, 111, 106, 0.08);
  color: var(--ink);
}

.warning-box {
  padding: 14px 16px;
  border: 1px solid rgba(204, 111, 74, 0.35);
  border-radius: 14px;
  background: rgba(204, 111, 74, 0.08);
  color: var(--ink);
}

.editor-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: var(--panel);
}

.editor-dialog::backdrop {
  background: rgba(31, 29, 26, 0.35);
}

.dialog-body {
  display: grid;
  gap: 16px;
  padding: 20px;
}
