:root {
  --bg: #0d1017;
  --panel: #151a23;
  --panel-2: #1b212c;
  --border: #28303d;
  --text: #e8edf4;
  --muted: #8a96a8;
  --accent: #2dd4bf;
  --accent-2: #f59e0b;
  --primary: #6366f1;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--border); gap: 12px; flex-wrap: wrap;
}
.brand { font-size: 16px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand b { font-weight: 700; }
.logo { color: var(--accent); font-size: 18px; }
.badge {
  background: var(--accent-2); color: #1a1205; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px; margin-left: 6px; text-transform: lowercase;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.theme-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.theme-field input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 10px; width: 160px; font-size: 13px;
}
.theme-field input:focus { outline: none; border-color: var(--accent); }

/* Buttons */
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 14px; font-size: 13px; cursor: pointer;
  transition: .15s; font-weight: 600;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }

/* Layout */
.layout { flex: 1; display: grid; grid-template-columns: 400px 1fr; min-height: 0; }
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

/* Chat */
.chat {
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--border); background: var(--panel);
}
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 11px 14px; border-radius: var(--radius); font-size: 14px; line-height: 1.5; max-width: 95%; }
.msg.system { background: var(--panel-2); color: var(--muted); border: 1px dashed var(--border); }
.msg.user { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 3px; }
.msg.bot { background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg.bot b { color: var(--accent); }
.msg.error { background: #3a1d22; border: 1px solid #7f1d1d; color: #fecaca; }

.controls {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px 0;
}
.age-field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.age-field select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 8px; font-size: 12px; cursor: pointer;
}
.mech-bar { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; flex: 1; }
.mech-bar::-webkit-scrollbar { height: 5px; }
.mech-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.chip {
  flex-shrink: 0; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 16px; padding: 6px 12px; font-size: 12px;
  cursor: pointer; white-space: nowrap; transition: .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #06231f; font-weight: 600; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 12px;
  border-top: 1px solid var(--border); background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  font-family: inherit; max-height: 140px; line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.mic {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel-2); cursor: pointer; font-size: 18px; flex-shrink: 0;
  transition: .15s;
}
.mic:hover { border-color: var(--accent); }
.mic.rec { background: #dc2626; border-color: #dc2626; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.5);} 50% { box-shadow: 0 0 0 8px rgba(220,38,38,0);} }
.send { width: 42px; height: 42px; padding: 0; font-size: 16px; flex-shrink: 0; }
.hint { padding: 0 14px 10px; font-size: 12px; color: var(--muted); min-height: 16px; }

/* Preview */
.preview { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.preview-head {
  display: flex; align-items: baseline; gap: 12px; padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.game-title { font-weight: 700; font-size: 15px; }
.game-meta { color: var(--muted); font-size: 12px; }
.stage { position: relative; flex: 1; margin: 16px; border-radius: 16px; overflow: hidden;
  background: #000; border: 1px solid var(--border); }
.stage iframe { border: 0; width: 100%; height: 100%; display: block; background: #fff; }

.overlay, .stage-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
}
.overlay { background: rgba(10,12,18,.82); backdrop-filter: blur(2px); z-index: 5; }
.overlay-text { color: var(--text); font-size: 14px; }
.stage-placeholder { background: var(--panel); color: var(--muted); font-size: 15px; }
.ph-emoji { font-size: 52px; opacity: .5; }
.spinner {
  width: 42px; height: 42px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* Drawer (gallery) */
.drawer {
  position: fixed; top: 0; right: 0; width: 340px; height: 100%; background: var(--panel);
  border-left: 1px solid var(--border); z-index: 30; display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,.4);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border); }
.gallery-list { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.gallery-item {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; cursor: pointer; transition: .15s;
}
.gallery-item:hover { border-color: var(--accent); }
.gallery-item .gi-title { font-weight: 600; font-size: 14px; }
.gallery-item .gi-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.gi-saved { color: var(--accent-2); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; width: 100%; max-width: 520px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input, .copy-row textarea {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font-size: 13px; font-family: ui-monospace, monospace;
  resize: none;
}
#shareOpen { display: inline-block; margin-top: 16px; text-decoration: none; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--accent); color: var(--text);
  padding: 11px 18px; border-radius: 10px; z-index: 50; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
