:root {
  --ocean0: #041620;
  --ocean1: #062b3d;
  --ocean2: #0f4f5c;
  --teal: #17b8a6;
  --gold: #f3c969;
  --line: rgba(255,255,255,.12);
  --glass: rgba(255,255,255,.07);
  --glass2: rgba(255,255,255,.1);
  --text: #e8f3f2;
  --muted: rgba(232,243,242,.66);
  --shadow: 0 18px 50px rgba(0,0,0,.35);
}

[data-theme="ocean"] {
  --bg-a: var(--ocean2);
  --bg-b: var(--ocean1);
  --bg-c: var(--ocean0);
  --accent: var(--teal);
  --accent-2: var(--gold);
}

[data-theme="sunset"] {
  --bg-a: #262136;
  --bg-b: #172d45;
  --bg-c: #121624;
  --accent: #ff7676;
  --accent-2: #ffc77c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 10%, rgba(47,208,191,.18) 0, transparent 38%),
    radial-gradient(circle at 80% 5%, rgba(243,201,105,.14) 0, transparent 45%),
    radial-gradient(circle at 50% 120%, rgba(23,184,166,.18) 0, transparent 55%),
    linear-gradient(180deg, var(--bg-a) 0%, var(--bg-b) 45%, var(--bg-c) 100%);
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-picker {
  position: relative;
}

.photo-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  min-width: 172px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8,31,42,.96);
  box-shadow: var(--shadow);
}

.photo-menu button {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  text-align: left;
  background: transparent;
  padding: 8px 10px;
}

.photo-menu button:hover {
  background: rgba(255,255,255,.1);
}

.map-grid {
  position: relative;
  min-height: 100vh;
  padding: 10px;
}

.map-grid::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255,255,255,.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: .22;
  mask-image: radial-gradient(circle at top, black 0, transparent 70%);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1160px, 100%);
  height: calc(100vh - 20px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.glass, .glass-strong {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.glass { background: var(--glass); }
.glass-strong { background: var(--glass2); }

.topbar {
  min-height: 104px;
  border-radius: 24px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 250px;
}

.brand-logo {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(0,0,0,.2);
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.35rem, 2.3vw, 1.75rem); line-height: 1.05; }
h2 { font-size: 1rem; }
p { color: var(--muted); line-height: 1.4; }

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.segmented, .tone-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 5px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(11,37,50,.62);
}

.needs-choice {
  border-color: color-mix(in srgb, var(--accent) 72%, transparent);
  background: color-mix(in srgb, var(--accent) 14%, rgba(11,37,50,.7));
  animation: choicePulse 1.15s ease-in-out infinite;
}

.segmented span, .tone-control span, .mini-card span {
  color: rgba(255,255,255,.6);
  font-size: .76rem;
}

.chip-button, .ghost-button, .icon-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,.06);
  border-radius: 14px;
  min-height: 32px;
  padding: 7px 12px;
}

.chip-button.active, .send-button, .generate-button, .preview-button {
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  color: white;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.chip-button:hover, .ghost-button:hover, .icon-button:hover {
  background: rgba(255,255,255,.1);
}

.tone-control input {
  width: 128px;
  accent-color: var(--accent);
}

.tone-control b {
  min-width: 92px;
  text-align: center;
  font-size: .76rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,.22);
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  gap: 12px;
}

.chat-panel, .brain-panel {
  min-height: 0;
  border-radius: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-head {
  min-height: 66px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: min(82%, 660px);
  padding: 12px 14px;
  border-radius: 20px;
  line-height: 1.45;
  animation: pop .16s ease-out;
  white-space: pre-wrap;
}

.message.bot {
  align-self: flex-start;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.12);
}

.message.user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 48%, transparent);
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 56px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  animation: typingDot 1s ease-in-out infinite;
}

.typing span:nth-child(2) { animation-delay: .16s; }
.typing span:nth-child(3) { animation-delay: .32s; }

.composer {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.mic-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,.06);
  border-radius: 16px;
  min-height: 54px;
  padding: 0 13px;
  font-weight: 800;
}

.mic-button.listening {
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  background: color-mix(in srgb, var(--accent) 24%, transparent);
  animation: choicePulse 1s ease-in-out infinite;
}

textarea {
  flex: 1;
  min-height: 54px;
  resize: none;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 13px 14px;
  outline: none;
  color: white;
  background: rgba(0,0,0,.2);
}

textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

textarea:disabled { opacity: .5; }

.send-button, .generate-button, .preview-button {
  border-radius: 18px;
  padding: 0 18px;
  min-height: 54px;
  font-weight: 800;
}

.input-hint {
  padding: 0 16px 12px;
  font-size: .78rem;
}

.brain-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mini-card {
  padding: 13px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(11,37,50,.52);
}

.mini-card strong {
  display: block;
  margin-top: 5px;
}

.facts-list {
  margin-top: 10px;
  display: grid;
  gap: 9px;
}

.fact {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: .88rem;
}

.fact em {
  color: rgba(255,255,255,.42);
  font-style: normal;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.12);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff5a5a, var(--accent-2));
  transition: width .25s ease;
}

.generate-button, .preview-button, .full {
  width: 100%;
}

.preview-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.preview-button[hidden] {
  display: none;
}

pre {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  color: rgba(255,255,255,.76);
  background: rgba(0,0,0,.24);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  padding: 12px;
}

.tips {
  margin-top: auto;
}

.tips ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: rgba(255,255,255,.72);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes typingDot {
  0%, 80%, 100% { transform: translateY(0); opacity: .42; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@keyframes choicePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 22%, transparent);
    transform: scale(1.018);
  }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: calc(100vh - 16px); }
  .topbar { align-items: flex-start; flex-direction: column; }
  .workspace { grid-template-columns: 1fr; }
  .chat-panel { min-height: 560px; }
  .brain-panel { min-height: 420px; }
}

@media (max-width: 560px) {
  .map-grid { padding: 0; }
  .map-grid::before { opacity: .12; }
  .app-shell { width: 100%; min-height: 100vh; gap: 8px; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 15;
    min-height: auto;
    border-radius: 0 0 18px 18px;
    padding: 9px;
    gap: 8px;
  }
  .brand { gap: 10px; min-width: 0; }
  .brand-logo { width: 48px; height: 48px; border-radius: 15px; }
  h1 { font-size: 1.2rem; }
  .brand p { font-size: .82rem; line-height: 1.25; }
  .controls {
    width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 3px;
    scrollbar-width: thin;
  }
  .controls > * { flex: 0 0 auto; }
  .segmented, .tone-control { min-height: 36px; border-radius: 15px; }
  .chip-button, .ghost-button, .icon-button { min-height: 29px; padding: 6px 10px; border-radius: 12px; }
  .tone-control input { width: 96px; }
  .tone-control b { min-width: 86px; }
  .workspace { gap: 8px; }
  .chat-panel, .brain-panel { border-radius: 18px; }
  .chat-panel { min-height: calc(100vh - 178px); }
  .panel-head { min-height: 54px; padding: 10px 12px; }
  .panel-head p { font-size: .86rem; }
  .chat-log { padding: 12px; gap: 10px; }
  .message { max-width: 96%; padding: 10px 12px; border-radius: 17px; font-size: .95rem; }
  .composer {
    position: sticky;
    bottom: 0;
    align-items: stretch;
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) 70px;
    gap: 8px;
    padding: 9px;
    background: rgba(6,27,37,.92);
    backdrop-filter: blur(12px);
  }
  .composer textarea {
    grid-column: 2;
    min-height: 50px;
    border-radius: 16px;
    padding: 12px;
  }
  .mic-button {
    grid-column: 1;
    grid-row: 1;
    min-height: 50px;
    padding: 0 8px;
    border-radius: 16px;
  }
  .send-button {
    grid-column: 3;
    grid-row: 1;
    min-height: 50px;
    padding: 0 10px;
    border-radius: 16px;
  }
  .input-hint { padding: 0 12px 10px; }
  .brain-panel { min-height: auto; max-height: 390px; }
  .brain-body { padding: 10px; gap: 9px; }
  .mini-card { padding: 11px; border-radius: 15px; }
  .facts-list { gap: 7px; }
  .fact { font-size: .82rem; }
  .tips { display: none; }
  .photo-menu { left: 0; right: auto; }
}
