:root {
  --bg: #0b1220;
  --panel: rgba(26, 19, 14, 0.84);
  --panel-solid: #1d1510;
  --line: rgba(255, 190, 120, 0.18);
  --text: #f6ead7;
  --muted: #b9a68c;
  --accent: #ff9a3c;
  --accent-2: #ffd27a;
  --danger: #ff7a66;
  --whisper: #c9bfff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 14px;
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ----------------------------------------------------------- HUD */

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

#topLeft {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 10px 12px;
  width: 210px;
  max-height: calc(100% - 110px);
  display: flex;
  flex-direction: column;
}
.brand { font-weight: 800; font-size: 16px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.brand .count { font-size: 12px; font-weight: 600; color: var(--muted); }
#online { margin-top: 6px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.who-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.who-row:hover { background: rgba(255, 255, 255, 0.06); }
.who-row canvas { width: 26px; height: 26px; flex: none; }
.who-row.me span { color: var(--accent-2); font-weight: 800; }
.who-row.idle { opacity: 0.55; }

#topRight { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(6px);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s, background 0.12s;
}
.icon-btn:hover { background: rgba(70, 48, 32, 0.9); transform: translateY(-1px); }
.icon-btn.flat { background: transparent; border-color: transparent; backdrop-filter: none; }
.icon-btn.flat:hover { background: rgba(255, 255, 255, 0.07); }

#logPanel {
  position: absolute;
  right: 12px;
  top: 62px;
  bottom: 82px;
  width: 310px;
  display: flex;
  flex-direction: column;
  padding: 10px 4px 10px 12px;
}
.panel-title { font-weight: 800; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
#log { overflow-y: auto; flex: 1; padding-right: 8px; display: flex; flex-direction: column; gap: 3px; }
.log-row { line-height: 1.35; overflow-wrap: anywhere; }
.log-row .time { color: rgba(185, 166, 140, 0.6); font-size: 11px; margin-right: 6px; }
.log-row .who { font-weight: 800; }
.log-row.me, .log-row.emote { color: #ffcf9a; font-style: italic; }
.log-row.whisper { color: var(--whisper); }
.log-row.sys { color: var(--muted); font-size: 12.5px; }

#chatbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
}
#chatInput {
  flex: 1;
  min-width: 0;
  height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(0, 0, 0, 0.3);
  padding: 0 12px;
  outline: none;
}
#chatInput:focus { border-color: rgba(255, 154, 60, 0.6); }

#emotePanel {
  position: absolute;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  width: min(620px, calc(100% - 24px));
  max-height: 46vh;
  overflow-y: auto;
  padding: 10px;
}
#emoteGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.emote-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.12s, transform 0.12s;
}
.emote-btn .icon { font-size: 22px; }
.emote-btn:hover { background: rgba(255, 154, 60, 0.16); border-color: rgba(255, 154, 60, 0.35); transform: translateY(-1px); }
.emote-btn:active { transform: scale(0.96); }

#banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #4a2a1a;
  border: 1px solid rgba(255, 154, 60, 0.5);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
}

/* ----------------------------------------------------------- buttons */

.primary {
  height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffad55, #f07f22);
  color: #2a1406;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 0 #a8501a;
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: 0.6; cursor: wait; }
.primary.big { height: 46px; font-size: 16px; width: 100%; }
.ghost {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  font-weight: 700;
}
.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.ghost.small { height: 30px; font-size: 12.5px; }

/* ----------------------------------------------------------- modals */

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(10, 8, 20, 0.35), rgba(5, 6, 14, 0.75));
  overflow-y: auto;
  z-index: 10;
}
.card {
  width: min(780px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.card header h1 { margin: 0; font-size: 26px; }
.card header p { margin: 4px 0 0; color: var(--muted); }
.card-grid { display: grid; grid-template-columns: 250px 1fr; gap: 22px; margin-top: 18px; }
.left { display: flex; flex-direction: column; gap: 12px; }
.left label { display: flex; flex-direction: column; gap: 5px; font-weight: 700; font-size: 13px; color: var(--muted); }
.left input {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  padding: 0 12px;
  color: var(--text);
  font-weight: 700;
  outline: none;
}
.left input:focus { border-color: rgba(255, 154, 60, 0.6); }
.error { color: var(--danger); min-height: 1.2em; font-weight: 700; font-size: 13px; }
.row-btns { display: flex; gap: 8px; justify-content: flex-end; }

.preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: radial-gradient(ellipse at 50% 100%, #2b3a2a, #141c18 70%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
}
canvas.preview { width: 220px; height: 160px; }

.controls { display: flex; flex-direction: column; gap: 9px; }
.ed-row { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 10px; }
.ed-label { color: var(--muted); font-weight: 700; font-size: 13px; }
.ed-body { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.seg {
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.seg.on { background: rgba(255, 154, 60, 0.22); border-color: var(--accent); }
.seg.arrow { width: 30px; padding: 0; font-size: 18px; }
.cycle-name { min-width: 80px; text-align: center; font-weight: 800; }
.sw {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s;
}
.sw:hover { transform: scale(1.12); }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
input.sw.custom {
  appearance: none;
  -webkit-appearance: none;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
  overflow: hidden;
}
input.sw.custom::-webkit-color-swatch-wrapper { padding: 0; opacity: 0; }
input.sw.custom::-moz-color-swatch { opacity: 0; }

/* ----------------------------------------------------------- small screens */

@media (max-width: 720px) {
  .card-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  #topLeft { width: auto; max-width: 52%; }
  #online { display: none; }
  #topRight { flex-wrap: wrap; justify-content: flex-end; max-width: 46%; }
  #btnZoomIn, #btnZoomOut { display: none; }
  #logPanel { left: 12px; right: 12px; width: auto; top: 62px; bottom: 76px; }
  .ed-row { grid-template-columns: 76px 1fr; }
}
