:root {
  --bg: #f2f2f2;
  --panel: #fafafa;
  --panel-alt: #f5f5f5;
  --panel-soft: #f0f0f0;
  --ink: #1c1c1c;
  --muted: #6b6f76;
  --accent: #5f6b74;
  --accent-dark: #49535a;
  --border: #d3d5d8;
  --sidebar-bg: #ededee;
  --splitter-bg: #efeff0;
  --splitter-border: #d7d9dc;
  --splitter-handle: #b4b8be;
  --menu-hover: #e4e6e8;
  --bg-gradient: radial-gradient(circle at top right, #f4f4f5, #e9eaec);
}

* {
  box-sizing: border-box;
  font-family: "Space Grotesk", "Avenir", sans-serif;
}

body {
  margin: 0;
  background: var(--bg-gradient);
  color: var(--ink);
}

body.dark {
  --bg: #16181b;
  --panel: #1f2226;
  --panel-alt: #24282d;
  --panel-soft: #2b3036;
  --ink: #f2f3f5;
  --muted: #b7bcc3;
  --accent: #9aa3ab;
  --accent-dark: #7f8790;
  --border: #3b4047;
  --sidebar-bg: #1b1e22;
  --splitter-bg: #20242a;
  --splitter-border: #2c3138;
  --splitter-handle: #5a626c;
  --menu-hover: #2a2f36;
  --bg-gradient: radial-gradient(circle at top right, #20242a, #14171b);
}

.app-shell {
  --sidebar-width: 260px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 18px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: width 0.15s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-name {
  font-weight: 700;
  font-size: 16px;
}

.app-logo {
  display: block;
  width: 92px;
  height: auto;
}

.sidebar-tools {
  display: grid;
  gap: 10px;
}

.sidebar-tools input {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

.sidebar-list {
  display: grid;
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
}

.canvas-item {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--panel-soft);
  font-size: 13px;
  display: grid;
  gap: 4px;
}

.canvas-item.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--panel) 88%);
}

.canvas-meta {
  font-size: 11px;
  color: var(--muted);
}

.sidebar-actions {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.app-shell.collapsed {
  grid-template-columns: 42px 12px 1fr;
}

.sidebar.collapsed {
  padding: 20px 8px;
}

.sidebar.collapsed .app-name,
.sidebar.collapsed .app-logo,
.sidebar.collapsed .sidebar-tools,
.sidebar.collapsed .sidebar-list,
.sidebar.collapsed .sidebar-actions {
  display: none;
}

.sidebar-toggle {
  position: fixed;
  left: 10px;
  top: 12px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  cursor: pointer;
  z-index: 50;
}

.hidden {
  display: none;
}

.content {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 40px 10px;
  gap: 12px;
}

.topbar-left {
  display: grid;
  gap: 2px;
}

.canvas-title {
  font-size: 22px;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  padding: 6px 4px;
  border-radius: 10px;
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}

.canvas-title:focus {
  border-color: var(--border);
  background: var(--panel-soft);
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.credit-pill {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
}

.user-name {
  font-size: 12px;
  color: var(--muted);
}

.user-menu {
  position: relative;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: 40px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 140px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
  z-index: 20;
}

.user-menu-item {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.user-menu-item:hover {
  background: var(--menu-hover);
}

.layout {
  --chat-width: 40%;
  display: grid;
  grid-template-columns: var(--chat-width) 18px 1fr;
  gap: 0;
  padding: 0 40px 40px;
  align-items: stretch;
}

.chat-panel,
.canvas-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 18px 18px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

.chat-panel {
  min-width: 240px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: calc(100vh - 140px);
  align-self: stretch;
  overflow: hidden;
}

.canvas-panel {
  min-width: 360px;
  height: calc(100vh - 140px);
  overflow: hidden;
}

.canvas-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.splitter {
  flex: 0 0 10px;
  position: relative;
  align-self: stretch;
  background: linear-gradient(
    to right,
    transparent 0%,
    transparent 45%,
    var(--splitter-border) 45%,
    var(--splitter-border) 55%,
    transparent 55%,
    transparent 100%
  );
  cursor: col-resize;
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  z-index: 2;
}

.sidebar-splitter {
  grid-column: 2;
}

.splitter-handle {
  width: 5px;
  height: 44px;
  border-radius: 999px;
  background: var(--splitter-handle);
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 1;
}

.splitter:hover .splitter-handle,
.splitter:focus-visible .splitter-handle {
  opacity: 1;
}

.chat-log {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-alt);
  flex: 1;
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.bubble {
  padding: 10px 12px;
  border-radius: 14px;
  max-width: 85%;
  line-height: 1.4;
  white-space: pre-wrap;
}

.bubble.user {
  justify-self: end;
  background: var(--accent);
  color: white;
}

.bubble.assistant {
  justify-self: start;
  background: var(--panel);
  border: 1px solid var(--border);
}

.chat-input {
  margin-top: auto;
  padding-top: 12px;
  display: grid;
  gap: 10px;
}

textarea {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--ink);
  resize: none;
  height: 80px;
  max-height: 80px;
  overflow-y: auto;
}

input {
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}

textarea::placeholder {
  color: var(--muted);
}

#messageInput {
  height: 80px;
  min-height: 80px;
  max-height: 80px;
  overflow-y: auto;
  resize: none !important;
}

.btn,
.btn-outline {
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  border: none;
  transition: 0.2s ease;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn {
  background: var(--accent);
  color: white;
}

.btn:hover {
  background: var(--accent-dark);
}

.btn-outline {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
}

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.login-card {
  background: white;
  padding: 40px;
  border-radius: 18px;
  border: 1px solid var(--border);
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

.canvas-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(200px, 1fr));
  grid-template-areas:
    "problem solution uvp customer"
    "unfair channels alternatives metrics"
    "concept early cost revenue";
  gap: 12px;
}

.canvas-cell {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--panel-alt);
  color: var(--ink);
}

.canvas-cell h3 {
  font-size: 15px;
  margin: 0 0 6px;
}

.canvas-cell textarea {
  width: 100%;
  min-height: 180px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  resize: vertical;
  color: var(--ink);
}

.cell-problem {
  grid-area: problem;
}
.cell-solution {
  grid-area: solution;
}
.cell-unique_value_proposition {
  grid-area: uvp;
}
.cell-unfair_advantage {
  grid-area: unfair;
}
.cell-customer_segments {
  grid-area: customer;
}
.cell-existing_alternatives {
  grid-area: alternatives;
}
.cell-key_metrics {
  grid-area: metrics;
}
.cell-high_level_concept {
  grid-area: concept;
}
.cell-channels {
  grid-area: channels;
}
.cell-early_adopters {
  grid-area: early;
}
.cell-cost_structure {
  grid-area: cost;
}
.cell-revenue_structure {
  grid-area: revenue;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.4);
}

.modal-card {
  position: relative;
  background: var(--panel);
  padding: 24px;
  border-radius: 18px;
  border: 1px solid var(--border);
  display: grid;
  gap: 12px;
  width: min(546px, 90vw);
}

.first-run-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

.modal-card input {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.modal-card select {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

.modal-card textarea {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  resize: vertical;
}

#promptEditor {
  min-height: 420px;
  max-height: 60vh;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.billing-pack-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.pack-card {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 4px;
  text-align: left;
  cursor: pointer;
}

.pack-card:hover {
  border-color: var(--accent);
}

.pack-card span {
  font-size: 12px;
  color: var(--muted);
}

.billing-settings {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.billing-settings h4 {
  margin: 0 0 8px;
}

.billing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.trial-disclaimer {
  font-size: 11px;
  color: var(--muted);
  padding: 8px 40px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.settings-label {
  font-size: 12px;
  color: var(--muted);
}

.settings-help {
  font-size: 12px;
  color: var(--muted);
  margin-top: -6px;
}

.made-by {
  font-size: 11px;
  color: var(--muted);
}

.theme-toggle {
  min-width: 44px;
  text-align: center;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar-toggle {
    display: none;
  }
  .sidebar-splitter {
    display: none;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .splitter {
    display: none;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .canvas-grid {
    grid-template-columns: 1fr;
    grid-template-areas: none;
  }
}

@media (max-width: 900px) {
  #messageInput {
    height: 72px;
    min-height: 72px;
    max-height: 72px;
  }
}

@media (max-width: 600px) {
  #messageInput {
    height: 64px;
    min-height: 64px;
    max-height: 64px;
  }
}

@media (max-width: 960px) and (orientation: landscape) {
  .app-shell {
    --sidebar-width: 168px;
    grid-template-columns: var(--sidebar-width) 12px 1fr;
    min-height: 100dvh;
  }

  .sidebar {
    border-right: 1px solid var(--border);
    border-bottom: none;
    padding: 12px 10px;
    gap: 10px;
  }

  .sidebar-splitter {
    display: grid;
  }

  .sidebar-toggle {
    display: none !important;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
  }

  .topbar-left p {
    display: none;
  }

  .canvas-title {
    font-size: 18px;
    padding: 4px 2px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .layout {
    grid-template-columns: 44% 12px 1fr;
    padding: 0 12px 12px;
    min-width: 0;
  }

  .splitter {
    display: grid;
    width: 12px;
    min-width: 12px;
  }

  .splitter-handle {
    opacity: 1;
  }

  .chat-panel,
  .canvas-panel {
    height: calc(100dvh - 74px);
    padding: 10px 12px 12px;
    min-width: 0;
  }

  .canvas-panel {
    overflow: auto;
  }

  .chat-toolbar {
    margin-bottom: 8px;
  }

  #messageInput {
    height: 64px;
    min-height: 64px;
    max-height: 64px;
  }

  .canvas-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
    grid-template-areas: none;
    gap: 8px;
  }

  .canvas-grid .canvas-cell {
    grid-area: auto !important;
    min-width: 0;
  }

  .canvas-cell {
    padding: 8px;
  }

  .canvas-cell textarea {
    min-height: 120px;
  }

  .trial-disclaimer {
    display: none;
  }

  .app-shell.collapsed {
    grid-template-columns: 34px 8px 1fr;
  }
}
