:root {
  --bg: #0e1116;
  --panel: #161b22;
  --border: #30363d;
  --text: #e8eaed;
  --muted: #8b949e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #f85149;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}
#game {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
}
#ui-root {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 30% 20%, #1a2332 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, #1a1520 0%, transparent 45%),
    var(--bg);
}
.panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.75rem 1.5rem 1.5rem;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.brand {
  font-size: 1.35rem; font-weight: 700; letter-spacing: .02em;
  margin: 0 0 .25rem; text-align: center;
}
.sub {
  text-align: center; color: var(--muted); margin: 0 0 1.25rem; font-size: .95rem;
}
label {
  display: block; font-size: .8rem; color: var(--muted); margin: .75rem 0 .3rem;
}
input, select {
  width: 100%; padding: .55rem .7rem;
  border-radius: 6px; border: 1px solid var(--border);
  background: #0d1117; color: var(--text); font-size: .95rem;
}
input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.btn {
  display: block; width: 100%; margin-top: .9rem; padding: .65rem;
  border: none; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; font-size: .95rem;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary {
  background: transparent; border: 1px solid var(--border); color: var(--text); font-weight: 500;
}
.btn.secondary:hover { border-color: var(--muted); }
.btn.danger { background: #3d1f1f; color: #ffa8a0; border: 1px solid #5c2b2b; }
.status {
  min-height: 1.25rem; margin-top: .85rem; text-align: center;
  font-size: .85rem; color: var(--danger);
}
.status.ok { color: #3fb950; }
.hint { font-size: .75rem; color: var(--muted); margin-top: .35rem; }
.char-list { list-style: none; padding: 0; margin: 0 0 1rem; max-height: 220px; overflow: auto; }
.char-list li {
  padding: .65rem .75rem; margin-bottom: .4rem;
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.char-list li:hover { border-color: var(--accent); background: #1c2330; }
.account { text-align: center; color: var(--muted); font-size: .85rem; margin-bottom: 1rem; }
#hud {
  position: fixed; left: 12px; bottom: 12px; z-index: 5;
  font-family: ui-monospace, monospace; font-size: 12px;
  background: rgba(0,0,0,.55); padding: 6px 10px; border-radius: 4px;
  pointer-events: none; display: flex; gap: 1rem;
}
#combat-ui {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
}
#combat-ui .float-win { pointer-events: auto; }
.unit-frame {
  width: 200px;
  background: rgba(14,17,22,.9);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.unit-name { font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.hp-bar {
  height: 10px; background: #21262d; border-radius: 4px; overflow: hidden;
}
.hp-fill { height: 100%; width: 100%; background: #3fb950; transition: width .15s; }
.hp-fill.target { background: #f85149; }
.hp-text { font-size: .7rem; color: var(--muted); margin-top: 3px; }
#hotbar {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
  max-width: min(920px, 96vw); pointer-events: auto;
}
#hotbar button {
  min-width: 52px; padding: 8px 8px;
  border-radius: 8px; border: 1px solid var(--border);
  background: rgba(22,27,34,.92); color: var(--text);
  font-weight: 600; cursor: pointer; font-size: .75rem;
}
#hotbar button:hover { border-color: var(--accent); }
#hotbar button.active { border-color: #d29922; color: #d29922; }
#combat-hint {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  font-size: .7rem; color: var(--muted); pointer-events: none;
}

#chat-host {
  position: fixed; inset: 0; z-index: 6;
  pointer-events: none;
}
.chat-panel {
  --float-alpha: 0.92;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  background: rgba(14, 17, 22, var(--float-alpha));
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(0,0,0,.4);
  min-width: 260px;
  min-height: 140px;
}
.chat-panel.float-has-alpha .float-titlebar,
.chat-panel.float-has-alpha .chat-tabs,
.chat-panel.float-has-alpha .chat-input-row {
  background: rgba(13, 17, 23, var(--float-alpha));
}
.chat-panel.float-has-alpha .chat-tab.active {
  background: rgba(22, 27, 34, var(--float-alpha));
}
.chat-panel.float-has-alpha .chat-input,
.chat-panel.float-has-alpha .chat-channel-select {
  background: rgba(22, 27, 34, max(0.55, var(--float-alpha)));
}
.float-win {
  z-index: 7;
  box-sizing: border-box;
}
.float-titlebar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 4px 6px 4px 10px;
  background: #0d1117; border-bottom: 1px solid var(--border);
  cursor: grab; user-select: none; flex-shrink: 0;
}
.float-win.pinned .float-titlebar { cursor: default; }
.float-title { font-size: .75rem; font-weight: 600; color: var(--muted); }
.float-actions { display: flex; gap: 2px; }
.float-btn {
  width: 24px; height: 22px; border: none; border-radius: 4px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: .75rem;
}
.float-btn:hover { background: #21262d; color: var(--text); }
.float-btn.active { color: #d29922; }
.float-resize {
  position: absolute; right: 0; bottom: 0; width: 14px; height: 14px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, #484f58 50%);
}
.float-win.pinned .float-resize { display: none; }
.ui-ctx-menu {
  position: fixed; z-index: 10000;
  min-width: 160px; padding: 4px;
  background: #161b22; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.ui-ctx-item {
  display: block; width: 100%; text-align: left;
  border: none; background: transparent; color: var(--text);
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: .85rem;
}
.ui-ctx-item:hover { background: #21262d; }
.ui-ctx-item:disabled { opacity: .4; cursor: default; }
.ui-ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }
#ui-win-tray {
  position: fixed; right: 12px; bottom: 12px; z-index: 8;
  display: none; flex-direction: column; gap: 6px;
}
.ui-tray-btn {
  pointer-events: auto;
  border: 1px solid var(--border); border-radius: 8px;
  background: rgba(22,27,34,.95); color: var(--text);
  padding: 8px 12px; cursor: pointer; font-size: .8rem;
}
.ui-tray-btn:hover { border-color: var(--accent); }
.unit-frame.float-win {
  width: 200px;
  background: rgba(14,17,22,.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
}
.unit-frame .unit-name,
.unit-frame .hp-bar,
.unit-frame .hp-text { margin-left: 10px; margin-right: 10px; }
.unit-frame .unit-name { margin-top: 6px; }
.unit-frame .hp-text { margin-bottom: 8px; }
.chat-tabs { display: flex; gap: 2px; padding: 6px 6px 0; background: rgba(13,17,23,0.92); flex-shrink: 0; }
.chat-tab {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 10px; border-radius: 6px 6px 0 0; cursor: pointer; font-size: .75rem;
}
.chat-tab:hover { color: var(--text); background: #1c2330; }
.chat-tab.active { color: var(--text); background: rgba(22,27,34,.95); border: 1px solid var(--border); border-bottom: none; }
.chat-log-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-log {
  height: auto; overflow-y: auto; padding: 8px 10px;
  font-size: .8rem; line-height: 1.35;
  font-family: ui-monospace, monospace;
  flex: 1;
  min-height: 80px;
}
.chat-line { margin-bottom: 3px; word-break: break-word; }
.chat-time { color: #6e7681; margin-right: 6px; }
.chat-name { cursor: pointer; text-decoration: underline dotted; }
.chat-name:hover { color: #c9a0ff; }
.chat-new-badge {
  position: absolute; right: 8px; bottom: 8px;
  background: var(--accent); color: #fff; border-radius: 10px;
  padding: 2px 8px; font-size: .7rem; cursor: pointer;
}
.chat-new-badge.hidden { display: none; }
.chat-input-row {
  display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border);
  background: rgba(13,17,23,0.92); flex-shrink: 0;
}
.chat-channel-select {
  width: 88px; flex-shrink: 0;
  background: #161b22; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; font-size: .75rem;
}
.chat-input {
  flex: 1; resize: none; min-height: 34px; max-height: 72px;
  background: #161b22; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: .85rem;
}
.chat-send-btn {
  width: 40px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--accent); color: #fff; cursor: pointer; font-weight: 700;
}
#speech-layer {
  position: fixed; inset: 0; pointer-events: none; z-index: 3;
}
.speech-bubble {
  position: absolute; left: 0; top: 0;
  max-width: 220px; padding: 6px 10px;
  background: rgba(14,17,22,.9); border: 1px solid var(--border);
  border-radius: 10px; font-size: .8rem; color: #e8dcc8;
  white-space: pre-wrap; word-break: break-word;
}
.speech-bubble.yell { color: #ffcc66; border-color: #8a6a20; }
