:root {
  color-scheme: light dark;
  --bg: #0f1115;
  --panel-bg: #161922;
  --border: #2a2e3a;
  --text: #e6e8ec;
  --text-dim: #9aa0ac;
  --accent: #6ea8fe;
  --accent-dim: #3d6bb0;
  --danger: #e5735a;
  --success: #5ec26a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#app-header h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.02em;
}

#npc-count {
  font-size: 12px;
  color: var(--text-dim);
}

#header-home-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
}

#header-home-link:hover {
  color: var(--text);
}

main {
  position: absolute;
  inset: 0;
  top: 52px;
}

#npc-grid-scroll {
  height: 100%;
  overflow-y: auto;
}

#npc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.npc-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 10px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.npc-card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-2px);
}

.npc-card.active {
  border-color: var(--accent);
  background: rgba(110, 168, 254, 0.08);
}

.npc-card-portrait {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg);
}

.npc-card-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: #0f1115;
}

.npc-card-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

#side-panel {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 20;
  animation: slide-in 0.18s ease-out;
}

@keyframes slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

#side-panel[hidden] {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  font-size: 16px;
  margin: 0;
}

#panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

#panel-close:hover {
  color: var(--text);
}

.panel-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0 0 12px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-label input {
  margin: 0;
}

input[type="text"], textarea {
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
}

button {
  background: var(--accent);
  color: #0f1115;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: #85b6ff;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

#save-status {
  min-height: 16px;
  font-size: 12px;
  margin-bottom: 8px;
}

#save-status.success { color: var(--success); }
#save-status.error { color: var(--danger); }

#chat-log {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.chat-message {
  font-size: 13px;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 8px;
  max-width: 90%;
}

.chat-message.player {
  align-self: flex-end;
  background: var(--accent-dim);
  color: #fff;
}

.chat-message.npc {
  align-self: flex-start;
  background: #1f2330;
  color: var(--text);
}

.chat-message.system {
  align-self: center;
  color: var(--text-dim);
  font-style: italic;
}

#chat-form {
  display: flex;
  gap: 8px;
}

#chat-form input {
  flex: 1;
  margin: 0;
}
