:root {
  --ink: #1a2330;
  --muted: #5c6b7a;
  --paper: #f3efe6;
  --paper-2: #e7e0d2;
  --accent: #0f6e56;
  --accent-2: #c45c26;
  --line: rgba(26, 35, 48, 0.12);
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(26, 35, 48, 0.12);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #dff1ea 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #f7d9c4 0%, transparent 50%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.brand-mark,
.brand-hero {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-mark { font-size: 1.25rem; color: var(--ink); text-decoration: none; }
.brand-hero {
  font-size: clamp(2.8rem, 8vw, 5.5rem);
  margin: 0 0 0.4rem;
  line-height: 0.95;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.02em; }
.lede { color: var(--muted); max-width: 42rem; }
.muted { color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  background: transparent;
  color: var(--ink);
}
.btn:hover { text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { border-color: var(--line); background: rgba(255,255,255,0.45); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 0.3rem 0.55rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.topbar form { margin: 0; }

.page-narrow { width: min(880px, calc(100% - 2rem)); margin: 1.5rem auto 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

.stack-form { display: grid; gap: 0.85rem; max-width: 420px; }
.stack-form label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.92rem; }
input, textarea, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: rgba(255,255,255,0.75);
  color: var(--ink);
}
.form-error { color: var(--danger); font-weight: 600; }

.auth-page, .landing { min-height: 100vh; }
.auth-shell {
  width: min(440px, calc(100% - 2rem));
  margin: 4rem auto;
  padding: 1.75rem;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.landing { position: relative; overflow: hidden; }
.landing-bg {
  position: absolute; inset: 0;
  background:
    linear-gradient(135deg, rgba(15,110,86,0.12), transparent 40%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%231a2330' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  z-index: 0;
}
.landing-nav, .landing-hero { position: relative; z-index: 1; }
.landing-nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.1rem 1.5rem;
}
.landing-nav nav { display: flex; gap: 0.6rem; }
.landing-hero {
  min-height: calc(100vh - 5rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem 1.5rem 4rem;
  animation: rise 700ms ease both;
}
.landing-hero h1 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 600;
  max-width: 18ch;
  margin: 0 0 0.75rem;
}
.cta-row { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 1.4rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.project-list { list-style: none; padding: 0; margin: 1.5rem 0; display: grid; gap: 0.75rem; }
.project-list a.project-main,
.project-row .project-main {
  display: grid; gap: 0.2rem;
  color: inherit;
  text-decoration: none;
  flex: 1;
  min-width: 0;
}
.project-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  background: rgba(255,255,255,0.65);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.project-row:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.project-list a.project-main:hover { text-decoration: none; }

.step-page { animation: rise 500ms ease both; }
.step-badge {
  display: inline-block;
  margin: 0 0 0.5rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: rgba(15,110,86,0.12);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
}
.step1-form { max-width: 520px; }
.unit-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.55);
}
.step1-form input[readonly] {
  background: rgba(0,0,0,0.04);
  color: var(--muted);
}
.conversion-hint { margin: 0; }

.editor-body { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.editor-topbar .editor-title {
  font-size: 1.05rem; margin: 0; flex: 1; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#editor-root {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(280px, 1fr) minmax(340px, 1.2fr);
  gap: 0;
}

.editor-pane {
  min-height: 0;
  overflow: auto;
  padding: 0.85rem;
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,0.35);
}
.editor-pane:last-child { border-right: none; }
.pane-title {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem; margin-bottom: 0.75rem;
}
.pane-title h2 { margin: 0; font-size: 1.05rem; }

.layer-list { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.35rem; }
.layer-item {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.4rem; padding: 0.45rem 0.55rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255,255,255,0.7); cursor: pointer;
}
.layer-item.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  margin: 0.6rem 0 1rem;
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.field-grid label, .full-field { display: grid; gap: 0.25rem; font-size: 0.82rem; font-weight: 600; }
.full-field { grid-column: 1 / -1; }

.preview-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
  min-height: 100%;
}
.preview-toolbar { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.preview-frame {
  position: relative;
  width: 100%;
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  background:
    linear-gradient(45deg, rgba(0,0,0,0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0,0,0,0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,0.04) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: auto;
  min-height: 280px;
}
.preview-frame img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  transition: opacity 180ms ease;
}
.preview-frame.loading img { opacity: 0.35; }
.preview-status {
  position: absolute; top: 0.6rem; right: 0.6rem;
  background: rgba(26,35,48,0.8); color: #fff;
  font-size: 0.75rem; padding: 0.25rem 0.5rem; border-radius: 999px;
  opacity: 0; transition: opacity 160ms ease;
}
.preview-frame.loading .preview-status { opacity: 1; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.cards-table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.cards-table th, .cards-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0;
  min-width: 96px;
}
.cards-table th { background: #f7f3ea; position: sticky; top: 0; z-index: 1; padding: 0.45rem; text-align: left; }
.cards-table tr.selected { background: rgba(15,110,86,0.08); }
.cards-table input {
  width: 100%; border: 0; border-radius: 0; background: transparent; padding: 0.45rem;
}
.cards-table input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.toolbar-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }
.import-box {
  margin-top: 0.85rem; padding: 0.75rem;
  border: 1px dashed var(--line); border-radius: 12px;
  background: rgba(255,255,255,0.45);
}
.import-box textarea { width: 100%; min-height: 90px; }
.status-line { min-height: 1.2em; font-size: 0.85rem; color: var(--muted); margin: 0.4rem 0; }
.status-line.error { color: var(--danger); }

@media (max-width: 1100px) {
  #editor-root {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    overflow: auto;
  }
  .editor-body { height: auto; overflow: auto; }
  .editor-pane { border-right: none; border-bottom: 1px solid var(--line); }
}
