:root {
  color-scheme: light;
  --ink: #18201c;
  --muted: #5b6961;
  --paper: #fbfcfb;
  --line: #cfd9d2;
  --field: #ffffff;
  --green: #2f7d4d;
  --green-dark: #215b39;
  --coral: #d95745;
  --gold: #e0b446;
  --teal: #3b8d8a;
  --shadow: 0 16px 45px rgba(31, 44, 37, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.login-page {
  min-height: 100%;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(47, 125, 77, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(47, 125, 77, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 30px 30px;
}

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

button,
.file-button,
.download-link {
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 0.62rem 0.78rem;
  text-decoration: none;
  transition: background 160ms ease, opacity 160ms ease, transform 160ms ease;
}

button:hover,
.file-button:hover,
.download-link:hover {
  background: var(--green-dark);
}

button:active,
.file-button:active,
.download-link:active {
  transform: translateY(1px);
}

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

.secondary {
  background: #edf3ef;
  color: var(--green-dark);
  border: 1px solid var(--line);
}

.secondary:hover {
  background: #e1ece5;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem clamp(0.75rem, 2vw, 1.25rem);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.choice-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(47, 125, 77, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(47, 125, 77, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 30px 30px;
}

.choice-inner {
  width: min(920px, 100%);
  display: grid;
  gap: 1rem;
}

.choice-inner h1 {
  max-width: 680px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: clamp(1rem, 4vw, 1.5rem);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 1.45rem;
}

.login-error {
  margin: 0;
  border: 1px solid #efc6bd;
  border-radius: 8px;
  background: #fff2ef;
  color: #9e3228;
  padding: 0.62rem;
  line-height: 1.4;
}

.project-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.project-card {
  min-height: 170px;
  display: grid;
  align-content: center;
  gap: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: clamp(1rem, 3vw, 1.5rem);
  text-align: left;
  box-shadow: var(--shadow);
}

.project-card:hover {
  background: #f4f8f5;
}

.project-card span {
  font-size: 1.35rem;
  font-weight: 800;
}

.project-card small {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.studio-view {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 780px;
  font-size: clamp(1.25rem, 2vw, 1.9rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.file-button input {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: end;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.workspace {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  padding: clamp(0.4rem, 0.9vw, 0.75rem);
  overflow: hidden;
}

.drop-zone {
  position: relative;
  display: grid;
  min-height: 0;
  flex: 0 1 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(47, 125, 77, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(47, 125, 77, 0.08) 1px, transparent 1px),
    #f6f9f6;
  background-size: 28px 28px;
  box-shadow: var(--shadow);
}

.drop-zone.dragging {
  outline: 3px solid rgba(217, 87, 69, 0.35);
}

#editorCanvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  touch-action: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.35rem;
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.empty-state strong {
  color: var(--ink);
  font-size: 1.25rem;
}

.toolbar,
.button-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.shape-tools {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.shape-button {
  border-radius: 0;
  background: #ffffff;
  color: var(--green-dark);
  padding: 0.56rem 0.68rem;
}

.shape-button:hover,
.shape-button.active {
  background: var(--green);
  color: #ffffff;
}

.toolbar {
  justify-content: space-between;
  padding-top: 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 0;
  padding: clamp(0.65rem, 1.2vw, 0.9rem);
  border-left: 1px solid var(--line);
  background: #ffffff;
  overflow: auto;
}

.panel-section {
  display: grid;
  flex: 0 0 auto;
  gap: 0.5rem;
}

.generate-section {
  gap: 0.65rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
}

.direction-section {
  display: grid;
  gap: 0.45rem;
  border-left: 4px solid var(--teal);
  background: #f3f8f6;
  padding: 0.7rem;
}

.direction-label {
  color: var(--ink);
  font-size: 0.98rem;
}

.field-control {
  display: grid;
  gap: 0.35rem;
}

.generation-actions {
  align-items: stretch;
}

.generation-actions button {
  flex: 1 1 0;
}

.prompt-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.45;
  padding: 0.62rem;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

#areaCount {
  min-width: 2rem;
  border-radius: 8px;
  background: #f2f5f3;
  color: var(--green-dark);
  font-weight: 800;
  padding: 0.25rem 0.55rem;
  text-align: center;
}

#historyCount {
  min-width: 2rem;
  border-radius: 999px;
  background: #f2f5f3;
  color: var(--green-dark);
  font-weight: 800;
  padding: 0.25rem 0.55rem;
  text-align: center;
}

.region-list {
  display: grid;
  gap: 0.5rem;
  max-height: min(30vh, 260px);
  overflow: auto;
}

.landscape-guide,
.interior-guide {
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--line);
}

.landscape-guide details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.58rem 0.65rem;
  background: #ffffff;
}

.landscape-guide details > :not(summary) {
  margin-top: 0.5rem;
}

.landscape-guide summary {
  cursor: pointer;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
}

.choice-step {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.step-header {
  width: 100%;
  display: grid;
  gap: 0.18rem;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  color: var(--ink);
  padding: 0.58rem 0.65rem;
  text-align: left;
}

.step-header:hover {
  background: #f4f8f5;
  color: var(--ink);
}

.step-header span {
  font-size: 0.9rem;
}

.step-header small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

.step-body {
  display: none;
  gap: 0.45rem;
  padding: 0 0.65rem 0.65rem;
}

.choice-step.open .step-body {
  display: grid;
}

.choice-step.open .step-header {
  background: #f7faf8;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
}

.choice-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--green-dark);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.2;
  padding: 0.42rem 0.52rem;
}

.choice-chip input {
  margin: 0;
}

.choice-chip:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.48;
}

.choice-chip:has(input:checked) {
  border-color: var(--green);
  background: #edf5ef;
  color: var(--ink);
}

.compact .choice-chip {
  font-size: 0.78rem;
}

.category-list {
  display: grid;
  gap: 0.42rem;
}

.change-choice {
  justify-self: start;
}

.specificity-group {
  display: grid;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 0.48rem;
}

.specificity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.87rem;
  font-weight: 800;
}

.category-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-top: 0.45rem;
}

.compact-button {
  justify-self: start;
  padding: 0.42rem 0.55rem;
  font-size: 0.82rem;
}

.selection-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.4;
}

.freeform-field {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.48rem;
}

.inline-option,
.history-reference {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.38rem;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.25;
}

.inline-option input,
.history-reference input {
  margin: 0;
}

.reference-section {
  padding-top: 0.2rem;
}

.reference-list {
  display: grid;
  gap: 0.45rem;
}

.reference-card {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 0.55rem;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 0.45rem;
}

.reference-card img {
  width: 74px;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #f4f6f5;
}

.reference-card > div {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.reference-ignored,
.region-validation {
  margin: 0;
  color: #9e3228;
  font-size: 0.78rem;
  line-height: 1.35;
}

.region-card:not(.missing-description) .region-validation {
  display: none;
}

.reference-card > textarea {
  grid-column: 1 / -1;
}

.optional-stack {
  gap: 0.45rem;
}

.optional-stack details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.48rem;
  background: #fbfcfb;
}

.optional-stack summary {
  cursor: pointer;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
}

.optional-stack details > :not(summary) {
  margin-top: 0.45rem;
}

.marked-areas-section.collapsed .region-list {
  display: none;
}

.advanced-section {
  display: block;
  border-top: 1px solid var(--line);
  padding-top: 0.35rem;
}

.advanced-section > summary {
  cursor: pointer;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 800;
}

.advanced-body {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.6rem;
}

.specificity-dialog {
  width: min(560px, calc(100% - 2rem));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.specificity-dialog::backdrop {
  background: rgba(24, 32, 28, 0.42);
}

.specificity-dialog form {
  display: grid;
  gap: 0.65rem;
  padding: 0.8rem;
}

.specificity-dialog header,
.specificity-dialog menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
}

.specificity-dialog .category-items {
  max-height: min(46vh, 360px);
  overflow: auto;
  padding-top: 0;
}

.empty-copy {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.region-card {
  display: grid;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-left: 6px solid var(--green);
  border-radius: 8px;
  padding: 0.62rem;
  background: var(--field);
}

.region-card.active {
  border-left-color: var(--coral);
}

.region-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.region-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.region-select {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.region-shape {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.region-label {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

.remove-region {
  padding: 0.45rem 0.6rem;
  background: #f8e9e6;
  color: #9e3228;
}

.remove-region:hover {
  background: #f3d5cf;
}

label {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  line-height: 1.45;
  min-height: 4.2rem;
  padding: 0.62rem;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  line-height: 1.45;
  padding: 0.56rem 0.62rem;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 0.56rem;
}

textarea:focus {
  outline: 3px solid rgba(59, 141, 138, 0.2);
  border-color: var(--teal);
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  outline: 3px solid rgba(59, 141, 138, 0.2);
  border-color: var(--teal);
}

.status {
  min-height: 1.4rem;
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.status.error {
  color: #9e3228;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  align-content: start;
  align-items: start;
  gap: 0.55rem;
  min-height: 0;
  padding-right: 0.15rem;
}

.history-section {
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
}

.history-detail {
  display: grid;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 0.62rem;
}

.history-detail strong {
  color: var(--ink);
  font-size: 0.85rem;
}

.history-detail p {
  max-height: 8rem;
  overflow: auto;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.history-item {
  display: grid;
  align-self: start;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 0.42rem;
  text-align: left;
  cursor: pointer;
}

.history-item.active {
  border-color: var(--coral);
}

.history-thumbnail {
  position: relative;
}

.history-thumbnail img {
  width: 100%;
  display: block;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #f4f6f5;
}

.delete-history {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  width: 1.7rem;
  height: 1.7rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  background: linear-gradient(180deg, #dc3b30 0%, #b8241b 100%);
  color: #ffffff;
  font-size: 0;
  font-weight: 900;
  line-height: 1;
  opacity: 0;
  padding: 0;
  box-shadow: 0 0.35rem 0.8rem rgba(63, 20, 17, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transform: scale(0.92);
  transition: opacity 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.delete-history::before,
.delete-history::after {
  content: "";
  position: absolute;
  width: 0.78rem;
  height: 2px;
  border-radius: 2px;
  background: #ffffff;
}

.delete-history::before {
  transform: rotate(45deg);
}

.delete-history::after {
  transform: rotate(-45deg);
}

.history-item:hover .delete-history,
.history-item:focus-within .delete-history {
  opacity: 1;
  transform: scale(1);
}

.delete-history:hover,
.delete-history:focus-visible {
  box-shadow: 0 0.45rem 0.95rem rgba(63, 20, 17, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transform: scale(1.04);
}

.history-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.history-reference-note {
  min-height: 3.3rem;
  font-size: 0.78rem;
}

.download-link {
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

.debug-panel {
  position: fixed;
  left: 0.75rem;
  bottom: 0.75rem;
  z-index: 10;
  width: min(680px, calc(100vw - 1.5rem));
  max-height: min(72vh, 680px);
  display: grid;
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 0.7rem;
}

.debug-panel.collapsed {
  width: auto;
  max-width: calc(100vw - 1.5rem);
  max-height: none;
  padding: 0.5rem;
}

.debug-panel[hidden] {
  display: none;
}

.debug-panel header,
.debug-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.debug-panel header {
  justify-content: space-between;
}

.debug-panel.collapsed header {
  gap: 0.75rem;
}

.debug-panel header > div:first-child {
  display: grid;
  gap: 0.1rem;
}

.debug-panel span,
.debug-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.debug-panel textarea {
  min-height: 220px;
  max-height: 44vh;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.76rem;
  white-space: pre;
}

.debug-panel code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.debug-panel.collapsed p,
.debug-panel.collapsed select,
.debug-panel.collapsed textarea,
.debug-panel.collapsed #copyDebugButton,
.debug-panel.collapsed #clearDebugButton {
  display: none;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .studio-view {
    height: auto;
    min-height: 100%;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .project-options {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .file-button,
  button {
    text-align: center;
    width: 100%;
  }

  .toolbar,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  #editorCanvas,
  .drop-zone {
    min-height: 260px;
  }
}
