:root {
  color-scheme: dark;
  --bg: #111522;
  --panel: rgba(24, 30, 43, 0.92);
  --panel-edge: rgba(255, 255, 255, 0.14);
  --text: #f7f3df;
  --muted: #b9c0bf;
  --accent: #ffd166;
  --danger: #f26d6d;
  --control: #283044;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  background: #132118;
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100vw - 32px));
  min-height: 480px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 28px;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
}

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

.mark {
  width: 32px;
  height: 32px;
  display: inline-block;
  background:
    linear-gradient(90deg, transparent 0 25%, #ffd166 25% 75%, transparent 75%),
    linear-gradient(transparent 0 20%, #5cc8ff 20% 80%, transparent 80%);
  image-rendering: pixelated;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.status {
  min-height: 24px;
  color: var(--muted);
}

.connection,
.character {
  min-height: 348px;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 18px;
}

.hidden {
  display: none !important;
}

label,
fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

label span,
legend {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: #111827;
  color: var(--text);
  outline: none;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segment,
.connect,
.play,
.chat-send {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.segment.selected {
  border-color: var(--accent);
  background: #374057;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 42px);
  gap: 10px;
}

.swatch {
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: var(--swatch);
  cursor: pointer;
}

.swatch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.28);
}

.connect,
.play {
  width: 100%;
  margin-top: auto;
  border-color: #ffd166;
  background: #ffd166;
  color: #1d2430;
  font-weight: 800;
}

.connect:disabled,
.play:disabled {
  border-color: rgba(255, 255, 255, 0.1);
  background: #596174;
  color: #ccd1d5;
  cursor: progress;
}

.hud {
  position: fixed;
  left: 16px;
  top: 16px;
  display: grid;
  gap: 4px;
  min-width: 146px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(15, 19, 28, 0.72);
  color: var(--text);
  font-size: 13px;
}

.hud span {
  color: var(--muted);
}

.chat {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: min(420px, calc(100vw - 32px));
  display: grid;
  grid-template-rows: minmax(112px, 180px) 42px;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(15, 19, 28, 0.72);
}

.chat-messages {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-right: 4px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.chat-line {
  overflow-wrap: anywhere;
}

.chat-line.system {
  color: #b9c0bf;
}

.chat-line.npc .chat-name {
  color: #ffd27a;
  font-weight: 800;
}

.chat-line.npc {
  color: #e8dfc0;
}

.chat-name {
  color: #ffd166;
  font-weight: 800;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
}

.chat-form input {
  min-height: 42px;
}

.chat-send {
  min-width: 76px;
  padding: 0 10px;
}

.menu {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 16, 0.58);
  backdrop-filter: blur(4px);
}

.menu-panel {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  background: rgba(24, 30, 43, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.menu-head strong {
  font-size: 16px;
}

.menu-section {
  display: grid;
  gap: 14px;
}

.menu-close,
.menu-apply {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.menu-apply {
  border-color: #ffd166;
  background: #ffd166;
  color: #1d2430;
  font-weight: 800;
}

@media (max-width: 520px) {
  .panel {
    min-height: min(500px, calc(100vh - 32px));
    padding: 20px;
  }

  h1 {
    font-size: 26px;
  }

  .chat {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    grid-template-rows: minmax(84px, 132px) 42px;
  }

  .menu-panel {
    width: calc(100vw - 20px);
    padding: 16px;
  }
}
