:root {
  color-scheme: dark;
  --ink: #f8fbff;
  --muted: #aab4c2;
  --panel: rgba(8, 11, 18, 0.82);
  --panel-strong: rgba(13, 18, 29, 0.94);
  --line: rgba(255, 255, 255, 0.16);
  --yellow: #ffd84d;
  --pink: #ff4f85;
  --cyan: #44d7ff;
  --green: #5ff28a;
  --red: #ff584f;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #03050b;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

#game-canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.screen,
.chapter-screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  pointer-events: auto;
}

.screen.is-visible,
.chapter-screen.is-visible {
  display: flex;
}

.select-shell {
  width: min(1120px, 100%);
  max-height: min(840px, calc(100vh - 32px));
  overflow: auto;
  padding: clamp(18px, 3vw, 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(8, 11, 18, 0.88), rgba(8, 11, 18, 0.76));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(18px);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.back-link,
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  text-decoration: none;
  font-size: 30px;
  line-height: 1;
}

.eyebrow,
#chapter-kicker,
#end-kicker,
.hud-card p {
  margin: 0 0 6px;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 0.95;
}

h1 {
  max-width: 820px;
  font-size: clamp(34px, 7vw, 84px);
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.character-card {
  min-height: 164px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  text-align: left;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.character-card:hover,
.character-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255, 216, 77, 0.72);
  outline: 0;
}

.character-card.is-selected {
  border-color: var(--cyan);
  background: rgba(68, 215, 255, 0.14);
}

.avatar-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--mark);
  color: #061018;
  font-size: 28px;
  font-weight: 900;
  box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.18);
}

.character-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 18px;
}

.character-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.stat-row {
  display: flex;
  gap: 5px;
  margin-top: 12px;
}

.stat-row i {
  display: block;
  width: 18px;
  height: 7px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.18);
}

.stat-row i.is-on {
  background: var(--green);
}

.select-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 20px;
}

.selected-strip {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.selected-strip span {
  display: block;
}

#selected-name {
  font-size: 20px;
  font-weight: 800;
}

#selected-role {
  color: var(--muted);
  font-size: 13px;
}

.primary-button,
.ghost-button,
.ghost-link {
  display: inline-grid;
  place-items: center;
  min-width: 132px;
  min-height: 46px;
  padding: 12px 18px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #061018;
  background: linear-gradient(135deg, var(--yellow), var(--green));
  font-weight: 900;
  text-decoration: none;
}

.ghost-button,
.ghost-link {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
}

.chapter-screen {
  background: rgba(0, 0, 0, 0.48);
}

.chapter-panel,
.mini-panel {
  width: min(560px, 100%);
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
}

.chapter-panel h2,
.mini-panel h2 {
  margin-bottom: 12px;
  font-size: clamp(36px, 8vw, 72px);
}

.chapter-panel p,
.mini-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.hud {
  position: fixed;
  top: 14px;
  left: 14px;
  display: none;
  gap: 10px;
  align-items: flex-start;
  pointer-events: none;
}

.hud.is-visible {
  display: flex;
}

.hud-card {
  width: min(330px, calc(100vw - 28px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.hud-card.compact {
  width: 150px;
}

.hud-card h2 {
  margin-bottom: 8px;
  font-size: 22px;
}

#hud-objective {
  min-height: 36px;
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.3;
}

.meter,
.health-bar {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
}

.meter span,
.health-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--cyan), var(--green), var(--yellow));
  transition: width 0.2s ease;
}

.health-bar span {
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--yellow));
}

.hud-row {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--ink);
  font-weight: 800;
}

.message {
  position: fixed;
  top: 18px;
  right: 18px;
  max-width: min(360px, calc(100vw - 36px));
  min-height: 44px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 216, 77, 0.42);
  background: rgba(14, 12, 4, 0.78);
  color: var(--yellow);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.message.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.tablet-controls {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  pointer-events: auto;
  touch-action: none;
}

.move-pad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 8px;
}

.move-pad button,
.action-pad button,
.look-pad {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.64);
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  touch-action: none;
}

.move-pad button,
.action-pad button {
  width: 64px;
  height: 64px;
  font-size: 24px;
}

.move-pad button:active,
.action-pad button:active,
.look-pad.is-active {
  border-color: rgba(255, 216, 77, 0.76);
  background: rgba(255, 216, 77, 0.18);
  transform: translateY(1px);
}

.move-pad [data-key="KeyW"] {
  grid-column: 2;
}

.move-pad [data-key="KeyA"] {
  grid-column: 1;
  grid-row: 2;
}

.move-pad [data-key="KeyD"] {
  grid-column: 3;
  grid-row: 2;
}

.move-pad [data-key="KeyS"] {
  grid-column: 2;
  grid-row: 2;
}

.look-pad {
  width: clamp(150px, 24vw, 240px);
  height: 112px;
  align-self: end;
  color: rgba(248, 251, 255, 0.76);
  font-size: 14px;
  text-transform: uppercase;
}

.action-pad {
  display: grid;
  grid-template-columns: 64px;
  gap: 8px;
}

.action-pad [data-key="ShiftLeft"] {
  color: #061018;
  background: linear-gradient(135deg, var(--yellow), var(--green));
}

.icon-button {
  position: fixed;
  right: 16px;
  top: 16px;
  z-index: 20;
  display: none;
  pointer-events: auto;
  font-size: 20px;
}

.icon-button.is-visible {
  display: grid;
}

.mini-panel {
  text-align: center;
}

.mini-panel .primary-button,
.mini-panel .ghost-button,
.mini-panel .ghost-link {
  width: 100%;
  margin-top: 10px;
}

@media (hover: none), (pointer: coarse), (max-width: 1180px) {
  .tablet-controls.is-visible {
    display: flex;
  }
}

@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait), (max-width: 720px) {
  .tablet-controls {
    align-items: end;
  }

  .look-pad {
    display: none;
  }
}

@media (max-width: 720px) {
  .screen,
  .chapter-screen {
    padding: 12px;
  }

  .select-shell {
    max-height: calc(100vh - 24px);
    padding: 14px;
  }

  .character-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .character-card {
    min-height: 144px;
  }

  .select-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button {
    width: 100%;
  }

  .hud {
    top: 10px;
    left: 10px;
    right: 10px;
    flex-direction: column;
  }

  .hud-card,
  .hud-card.compact {
    width: min(300px, calc(100vw - 20px));
  }

  .message {
    top: auto;
    right: 10px;
    bottom: 164px;
    left: 10px;
  }

  .tablet-controls {
    left: 10px;
    right: 10px;
    bottom: 10px;
    gap: 10px;
  }

  .move-pad {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    gap: 7px;
  }

  .move-pad button,
  .action-pad button {
    width: 56px;
    height: 56px;
  }

  .action-pad {
    grid-template-columns: 56px;
  }
}


/* ===== Editor kol ===== */
.custom-panel { max-width: 420px; max-height: 90vh; overflow-y: auto; text-align: left; }
.custom-note { opacity: 0.75; font-size: 0.9rem; margin-bottom: 0.6rem; }
.custom-field { display: block; font-size: 0.85rem; margin-bottom: 0.55rem; opacity: 0.9; }
.custom-field input[type="text"], .custom-field select {
  display: block; width: 100%; margin-top: 0.25rem; padding: 0.5rem 0.7rem;
  border-radius: 10px; border: 1px solid rgba(160,180,220,0.35);
  background: rgba(10,14,26,0.8); color: #eef2ff; font: inherit;
}
.custom-field input[type="range"] { display: block; width: 100%; margin-top: 0.3rem; }
.custom-field output { float: right; font-weight: 700; color: #ffd84d; }
.custom-actions { display: flex; gap: 0.5rem; margin: 0.7rem 0; }
.custom-list { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.7rem; max-height: 26vh; overflow-y: auto; }
.custom-row {
  display: flex; align-items: center; gap: 0.4rem;
  background: rgba(20,26,44,0.8); border: 1px solid rgba(160,180,220,0.25);
  border-radius: 10px; padding: 0.3rem 0.6rem;
}
.custom-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.custom-row button {
  background: rgba(68,215,255,0.15); border: 1px solid rgba(68,215,255,0.4);
  color: #eef2ff; border-radius: 8px; padding: 0.15rem 0.55rem; cursor: pointer; font: inherit;
}
.custom-empty { opacity: 0.6; font-size: 0.9rem; }
