:root {
  --bg: #16171b;
  --panel: rgba(42, 45, 52, 0.92);
  --input: #1f2126;
  --hover: #343842;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8eaed;
  --soft: #c4c8d0;
  --muted: #9aa1ac;
  --accent: #6d7cff;
  --accent-hover: #5866e8;
  --danger: #ed4245;
  --warn: #f0b232;
  --radius: 16px;
  --font: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.65;
}

.atmosphere { display: none; }

.char-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  display: none;
  background-color: var(--bg);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}
.char-bg.visible { display: block; }
.char-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(24, 25, 28, 0.42), rgba(24, 25, 28, 0.22) 45%, rgba(24, 25, 28, 0.5));
}
body.chat-open .char-bg.visible::after {
  background: linear-gradient(180deg, rgba(24, 25, 28, 0.28), rgba(24, 25, 28, 0.08) 42%, rgba(24, 25, 28, 0.38));
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 820px;
  margin: 0 auto;
  padding: 18px 18px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.kicker, h1 { display: none; }

h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.bg-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  color: var(--soft);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.bg-toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(20, 22, 26, 0.72);
}
.tab, button, select, input, textarea {
  font-family: inherit;
  color: var(--text);
}

.tab, .ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--soft);
  font-size: 14px;
}
.tab {
  border: 0;
  border-radius: 9px;
  padding: 8px 16px;
  font-weight: 600;
}
.tab span {
  margin-left: 6px;
  color: var(--muted);
  font-size: 13px;
}
.tab.active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.tab.active span { color: rgba(255, 255, 255, 0.82); }
.tab:hover, .ghost:hover {
  background: var(--hover);
  color: var(--text);
}
.tab.active:hover {
  background: var(--accent-hover);
  color: #fff;
}

.primary {
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.primary:hover { background: var(--accent-hover); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }

.danger {
  color: var(--danger);
  border-color: rgba(237, 66, 69, 0.45);
}
.danger:hover {
  background: rgba(237, 66, 69, 0.12);
  color: rgb(255, 180, 182);
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.preset-grid label,
.preset-grid .voice-tone-wrap {
  margin: 0;
}
.preset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
#generateImageBtn {
  white-space: nowrap;
}
#preset-msg { min-height: 1.2em; margin: 10px 0 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
}
.panel-world {
  margin-bottom: 0;
}
.panel-world textarea {
  min-height: 220px;
}
#view-settings {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: calc(100vh - 108px);
  padding-bottom: 24px;
}
#view-settings.hidden { display: none !important; }

.panel-head, .actions, .chat-meta, .counter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.panel-head { margin-bottom: 10px; }
.panel-world .hint { margin: 0 0 12px; }
.panel-world .hint strong { color: var(--soft); font-weight: 600; }
.world-guide {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(20, 22, 26, 0.45);
}
.world-guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--soft);
  font-size: 13px;
  font-weight: 600;
}
.world-guide-head .ghost {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
}
.world-guide-body {
  margin: 0;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: keep-all;
}
.panel-world textarea::placeholder {
  color: rgb(124, 130, 140);
  white-space: pre-wrap;
  line-height: 1.65;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--soft);
}

.chip {
  display: none;
}

.status-pill, .msg-role {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 13px;
}

input, select, textarea {
  background: var(--input);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: none;
}

textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
}

.hint, .muted, .counter-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.hidden { display: none !important; }

.counter {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--input);
}
.counter-kicker {
  font-size: 12px;
  color: var(--muted);
}
.counter-readout {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.counter-readout strong { color: var(--text); font-weight: 600; }
.counter-readout em {
  margin: 0 4px;
  font-style: normal;
  color: var(--muted);
  font-weight: 500;
}
.counter-readout span { color: var(--muted); font-weight: 500; }

.meter {
  height: 4px;
  margin: 10px 0 8px;
  border-radius: 999px;
  background: rgb(54, 57, 63);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.16s ease;
}

.counter.warn .counter-readout strong,
.counter.warn .counter-status { color: var(--warn); }
.counter.warn .meter-fill { background: var(--warn); }
.counter.max .counter-readout strong,
.counter.max .counter-status { color: var(--danger); }
.counter.max .meter-fill { background: var(--danger); }

.chat-meta {
  justify-content: space-between;
  min-height: 20px;
  margin-bottom: 4px;
}
.chat-meta .status-pill {
  font-size: 13px;
  color: var(--soft);
}
.voice-tone-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.voice-tone-wrap select {
  min-width: 180px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--text);
}
.voice-tone-chat {
  margin: 0;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.voice-tone-chat select {
  min-width: 168px;
  padding: 6px 8px;
}

.chat-stage {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 108px);
}

#view-chat .chat-stage {
  background: transparent;
  padding: 8px 0 0;
}

body.chat-open .topbar {
  background: rgba(24, 25, 28, 0.35);
  backdrop-filter: blur(10px);
  border-bottom-color: rgba(255, 255, 255, 0.08);
  margin: -18px -18px 16px;
  padding: 12px 18px;
  border-radius: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 2px 18px;
}

.msg {
  max-width: 80%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg.system {
  align-self: center;
  max-width: 92%;
}
.msg.system .msg-body {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  padding: 0;
}
.msg.policy .msg-body {
  color: var(--warn);
  background: rgba(240, 178, 50, 0.12);
  border-radius: 999px;
  padding: 8px 14px;
}

.msg-role { font-size: 12px; }
.msg.user .msg-role { color: var(--muted); }

.msg-body {
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--input);
  white-space: pre-wrap;
  line-height: 1.75;
  font-size: 16px;
  color: var(--text);
}
.msg.user .msg-body {
  background: rgb(49, 51, 56);
  border-bottom-right-radius: 6px;
}
.msg.assistant .msg-body {
  background: rgb(35, 36, 40);
  border-bottom-left-radius: 6px;
}
.msg-line {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.speak-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(32, 34, 37, 0.58);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.speak-btn:hover { border-color: rgba(88, 101, 242, 0.7); }
.speak-btn:disabled { opacity: 0.45; cursor: default; }
.speak-btn.playing {
  border-color: rgba(88, 101, 242, 0.9);
  animation: speak-pulse 1s ease-in-out infinite;
}
@keyframes speak-pulse {
  50% { transform: scale(1.08); }
}
body.chat-open .msg.user .msg-body {
  background: rgba(49, 51, 56, 0.72);
  backdrop-filter: blur(10px);
}
body.chat-open .msg.assistant .msg-body {
  background: rgba(24, 25, 28, 0.55);
  backdrop-filter: blur(10px);
}

.msg.streaming .msg-body::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 3px;
  background: var(--soft);
  vertical-align: text-bottom;
  animation: blink 0.9s steps(1) infinite;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  color: var(--muted);
  font-size: 13px;
}
.dots { display: flex; gap: 5px; }
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--soft);
  opacity: 0.3;
  animation: bounce 1.05s infinite;
}
.dots i:nth-child(2) { animation-delay: 0.14s; }
.dots i:nth-child(3) { animation-delay: 0.28s; }

.scene-dock {
  position: relative;
  margin-top: 4px;
}
.scene-pop {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 5;
}
.scene-pop-form {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(32, 34, 37, 0.92);
  border: 1px solid rgba(88, 101, 242, 0.55);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(16px);
}
.scene-pop-label {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.scene-pop-form input {
  width: 100%;
  background: rgba(24, 25, 28, 0.72);
}
.scene-pop-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.scene-pop-actions .ghost,
.scene-pop-actions .primary {
  padding: 8px 14px;
  border-radius: 10px;
}
.scene-pop-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.scene-skips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.scene-skips::-webkit-scrollbar { display: none; }
.scene-chip {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(32, 34, 37, 0.58);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--soft);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.3;
}
.scene-chip:hover {
  background: rgba(88, 101, 242, 0.24);
  border-color: rgba(88, 101, 242, 0.45);
  color: var(--text);
}
.scene-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.scene-chip-custom {
  color: var(--text);
  border-color: rgba(88, 101, 242, 0.78);
  background: rgba(88, 101, 242, 0.18);
  box-shadow: inset 0 0 0 1px rgba(88, 101, 242, 0.22);
}
.scene-chip-custom:hover,
.scene-chip-custom[aria-expanded="true"] {
  background: rgba(88, 101, 242, 0.32);
  border-color: rgba(88, 101, 242, 0.95);
  color: var(--text);
}

.mic-status {
  margin: 0 4px 8px;
  font-size: 13px;
  color: var(--muted, #9aa0a6);
}
.mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line, #3a3d42);
  background: var(--input, #2b2d31);
  cursor: pointer;
}
.mic-btn.listening {
  border-color: #f23f5a;
  box-shadow: 0 0 0 3px rgba(242, 63, 90, 0.28);
}
.composer {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: end;
  padding: 8px;
  border-radius: 16px;
  background: var(--input);
}
body.chat-open .composer {
  background: rgba(32, 34, 37, 0.7);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.composer textarea {
  min-height: 72px;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 10px 12px;
  color: var(--text);
}
.composer.busy { outline: 1px solid var(--line); }

@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.28; }
  40% { transform: translateY(-3px); opacity: 1; }
}

.slot-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.slot-toolbar .primary { min-width: 140px; }
.slot-list {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding-bottom: 8px;
}
.slot-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(31, 33, 38, 0.85);
}
.slot-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.slot-card-head input {
  flex: 1;
  min-width: 0;
}
.slot-card textarea {
  min-height: 88px;
}
.slot-card .counter { margin-top: 8px; }

@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .msg { max-width: 94%; }
  .preset-grid { grid-template-columns: 1fr; }
  .shell { padding: 12px 12px 32px; }
  .panel { padding: 16px; }
  .panel-world textarea { min-height: 180px; }
}

.notice-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 9, 12, 0.72);
  backdrop-filter: blur(8px);
}
.notice-overlay[hidden] { display: none; }
.notice-modal {
  width: min(520px, 100%);
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}
.notice-modal h2 {
  margin-bottom: 10px;
  font-size: 17px;
}
.notice-modal p {
  margin: 0 0 18px;
  color: var(--soft);
  font-size: 15px;
  line-height: 1.75;
  word-break: keep-all;
}
.notice-modal .primary {
  width: 100%;
  min-height: 42px;
}
body.notice-open { overflow: hidden; }
