* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f0f14;
  color: #e8e8ec;
  height: 100vh;
}

button,
input {
  font: inherit;
}

.layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #121218;
  border-right: 1px solid #23232b;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  transition: margin-left 0.2s ease;
}

.sidebar.collapsed {
  margin-left: -260px;
}

.new-chat-btn {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #2a2a33;
  background: #1c1c24;
  color: #e8e8ec;
  font-weight: 600;
  cursor: pointer;
}

.new-chat-btn:hover {
  background: #24242e;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: #c9c9d1;
  gap: 8px;
}

.chat-list-item:hover {
  background: #1c1c24;
}

.chat-list-item.active {
  background: #24242e;
  color: #e8e8ec;
}

.chat-list-item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.chat-list-item-delete {
  background: none;
  border: none;
  color: #8b8b96;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}

.chat-list-item-delete:hover {
  background: #ed4245;
  color: white;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex: 1;
  max-width: 760px;
  margin: 0 auto;
  min-width: 0;
}

header {
  padding: 18px 20px;
  font-size: 20px;
  font-weight: 600;
  border-bottom: 1px solid #23232b;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title {
  flex: 1;
}

.sidebar-toggle {
  background: none;
  border: 1px solid #2a2a33;
  color: #e8e8ec;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 16px;
}

.sidebar-toggle:hover {
  background: #1c1c24;
}

.games-header-btn {
  border: 1px solid #2a2a33;
  background: #1c1c24;
  color: #e8e8ec;
  border-radius: 8px;
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
  font-weight: 600;
}

.games-header-btn:hover {
  background: #24242e;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat.games-open {
  display: none;
}

.msg {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: #4f46e5;
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: #1c1c24;
  border-bottom-left-radius: 4px;
}

.msg.typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8b8b96;
  animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(2) {
  animation-delay: 0.15s;
}

.dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.input-bar {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid #23232b;
}

.input-bar.games-open {
  display: none;
}

.input-bar input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #2a2a33;
  background: #16161c;
  color: #e8e8ec;
  font-size: 15px;
  outline: none;
}

.input-bar input:focus {
  border-color: #4f46e5;
}

.input-bar button {
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  background: #4f46e5;
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.input-bar button:hover {
  background: #433cd1;
}

.footer-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  font-size: 12px;
  color: #6b6b76;
  padding: 10px 20px 16px;
  border-top: 1px solid #1a1a20;
  margin-top: -1px;
}

.footer-note-icon {
  flex-shrink: 0;
  color: #55555f;
}

.code-block {
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2a2a33;
  background: #0d0d12;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: #1a1a22;
  border-bottom: 1px solid #2a2a33;
}

.code-lang {
  font-size: 12px;
  color: #8b8b96;
  text-transform: lowercase;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.code-copy-btn {
  background: none;
  border: 1px solid #2a2a33;
  color: #c9c9d1;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.code-copy-btn:hover {
  background: #24242e;
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
}

.code-block code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #e8e8ec;
  white-space: pre;
}

#commands-btn {
  background: #1c1c24;
  color: #8b8b96;
  font-weight: 700;
  padding: 12px 16px;
}

#commands-btn:hover {
  background: #24242e;
}

.dropdown {
  margin: 0 20px;
  max-height: 220px;
  overflow-y: auto;
  background: #16161c;
  border: 1px solid #2a2a33;
  border-radius: 10px;
}

.dropdown.hidden {
  display: none;
}

.dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #23232b;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: #1c1c24;
}

.dropdown-item .cmd-name {
  color: #a5a1ff;
  font-weight: 600;
}

.dropdown-item .cmd-desc {
  color: #8b8b96;
  font-size: 13px;
  margin-top: 2px;
}

.cmd-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cmd-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.badge-live {
  background: rgba(87, 242, 135, 0.15);
  color: #57f287;
}

.badge-chat {
  background: rgba(139, 139, 150, 0.15);
  color: #8b8b96;
}

.dropdown-item.chat-only {
  opacity: 0.7;
}

.dropdown-item.working:last-of-type {
  border-bottom: 2px solid #2a2a33;
}

.msg.embed {
  border-left: 4px solid #5865f2;
  background: #16161c;
  max-width: 85%;
  padding: 12px 16px;
}

.embed-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.embed-desc {
  color: #c9c9d1;
  white-space: pre-wrap;
  margin-bottom: 8px;
}

.embed-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.embed-field {
  min-width: 100px;
}

.embed-field-name {
  font-size: 12px;
  color: #8b8b96;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.embed-field-value {
  font-weight: 600;
  margin-top: 2px;
}

.spoiler {
  display: inline-block;
  background: #1c1c24;
  color: transparent;
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  user-select: none;
  transition: color 0.1s;
}

.spoiler.revealed {
  color: #e8e8ec;
  cursor: text;
}

.embed-image {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  margin-top: 10px;
  border: 1px solid #2a2a33;
}

.hidden {
  display: none !important;
}

.games-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 20px 28px;
}

.games-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.games-panel-header h1 {
  margin: 0;
  font-size: 26px;
}

.games-panel-header p {
  margin: 5px 0 0;
  color: #8b8b96;
  font-size: 14px;
}

.games-close-btn {
  width: 36px;
  height: 36px;
  border: 1px solid #2a2a33;
  background: #1c1c24;
  color: #e8e8ec;
  border-radius: 9px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.games-close-btn:hover {
  background: #24242e;
}

.game-menu {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 230px;
  padding: 20px;
  border: 1px solid #2a2a33;
  border-radius: 14px;
  background: #16161c;
  color: #e8e8ec;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.game-card:hover {
  transform: translateY(-2px);
  background: #1c1c24;
  border-color: #4f46e5;
}

.game-card-icon {
  font-size: 38px;
  margin-bottom: 14px;
}

.game-card-title {
  font-size: 19px;
  font-weight: 700;
}

.game-card-desc {
  color: #8b8b96;
  font-size: 13px;
  line-height: 1.45;
  margin-top: 7px;
}

.game-card-play {
  margin-top: auto;
  padding-top: 18px;
  color: #a5a1ff;
  font-weight: 700;
}

.game-stage {
  min-height: 0;
}

.game-view {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}

.game-back-btn {
  border: 1px solid #2a2a33;
  background: #1c1c24;
  color: #c9c9d1;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  margin-bottom: 18px;
}

.game-back-btn:hover {
  background: #24242e;
}

.game-view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.game-view-icon {
  font-size: 34px;
}

.game-view-header h2 {
  margin: 0;
  font-size: 23px;
}

.game-view-header p {
  margin: 3px 0 0;
  color: #8b8b96;
  font-size: 13px;
}

.snake-stats,
.trivia-stats,
.hl-stats {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  color: #c9c9d1;
  font-size: 13px;
  font-weight: 600;
}

.snake-canvas {
  display: block;
  width: min(100%, 360px);
  height: auto;
  aspect-ratio: 1;
  margin: 0 auto;
  border: 1px solid #2a2a33;
  border-radius: 12px;
  touch-action: none;
  background: #0b0b10;
}

.snake-controls {
  width: 190px;
  margin: 15px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.snake-control {
  width: 58px;
  height: 46px;
  border: 1px solid #2a2a33;
  border-radius: 9px;
  background: #1c1c24;
  color: #e8e8ec;
  cursor: pointer;
  font-size: 20px;
  justify-self: center;
  touch-action: manipulation;
}

.snake-control:hover {
  background: #24242e;
}

.game-status {
  min-height: 22px;
  margin: 15px 0 12px;
  text-align: center;
  color: #c9c9d1;
  font-size: 14px;
}

.game-primary-btn {
  display: block;
  margin: 0 auto;
  border: none;
  border-radius: 9px;
  background: #4f46e5;
  color: white;
  padding: 11px 18px;
  font-weight: 700;
  cursor: pointer;
}

.game-primary-btn:hover {
  background: #433cd1;
}

.trivia-question {
  padding: 20px;
  border: 1px solid #2a2a33;
  border-radius: 12px;
  background: #16161c;
  text-align: center;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 14px;
}

.trivia-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.trivia-answer {
  min-height: 54px;
  padding: 12px;
  border: 1px solid #2a2a33;
  border-radius: 10px;
  background: #1c1c24;
  color: #e8e8ec;
  cursor: pointer;
  text-align: left;
}

.trivia-answer:hover:not(:disabled) {
  background: #24242e;
  border-color: #4f46e5;
}

.trivia-answer:disabled {
  cursor: default;
}

.trivia-answer.correct {
  border-color: #57f287;
  background: rgba(87, 242, 135, 0.13);
}

.trivia-answer.incorrect {
  border-color: #ed4245;
  background: rgba(237, 66, 69, 0.13);
}

.hl-number {
  width: 180px;
  height: 180px;
  margin: 18px auto 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid #2a2a33;
  background: #16161c;
  font-size: 58px;
  font-weight: 800;
  color: #a5a1ff;
}

.hl-pop {
  animation: hlPop 0.2s ease;
}

@keyframes hlPop {
  50% {
    transform: scale(1.06);
  }
}

.hl-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 460px;
  margin: 0 auto;
}

.hl-btn {
  padding: 15px;
  border: 1px solid #2a2a33;
  border-radius: 10px;
  background: #1c1c24;
  color: #e8e8ec;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
}

.hl-btn:hover:not(:disabled) {
  background: #24242e;
  border-color: #4f46e5;
}

.hl-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.hl-result {
  min-height: 44px;
  margin: 18px auto;
  max-width: 500px;
  text-align: center;
  color: #c9c9d1;
  line-height: 1.5;
}

@media (max-width: 700px) {
  .sidebar {
    position: fixed;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.35);
  }

  .sidebar.collapsed {
    margin-left: -260px;
  }

  .app {
    max-width: none;
  }

  header {
    padding: 14px;
  }

  .games-header-btn {
    padding: 0 9px;
    font-size: 13px;
  }

  .chat {
    padding: 14px;
  }

  .input-bar {
    padding: 12px 14px;
  }

  .footer-note {
    padding-bottom: 12px;
  }

  .games-panel {
    padding: 18px 14px 24px;
  }

  .game-menu {
    grid-template-columns: 1fr;
  }

  .game-card {
    min-height: 170px;
  }

  .trivia-answers {
    grid-template-columns: 1fr;
  }

  .hl-number {
    width: 155px;
    height: 155px;
    font-size: 48px;
  }
}

@media (max-width: 420px) {
  .header-title {
    font-size: 18px;
  }

  .games-header-btn {
    font-size: 12px;
  }

  .game-view-header h2 {
    font-size: 21px;
  }

  .snake-controls {
    width: 180px;
  }

  .snake-control {
    width: 54px;
    height: 44px;
  }
}

.msg.imagine-generation {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 440px;
  max-width: 85%;
  min-height: 280px;
  padding: 0;
  overflow: hidden;
  isolation: isolate;
  white-space: normal;
  background: radial-gradient(ellipse at 50% 40%, #1d1838 0%, #121220 55%, #0d0d14 100%);
  border: 1px solid #2a2a40;
  border-radius: 14px 14px 14px 4px;
  transition: opacity 0.22s ease, transform 0.22s ease;
  animation: imagineAppear 0.4s ease;
}

.msg.imagine-generation.imagine-generation-finished {
  opacity: 0;
  transform: scale(0.97);
}

.imagine-generation-glow {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 240px;
  height: 240px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(130, 100, 255, 0.3), rgba(130, 100, 255, 0) 70%);
  filter: blur(14px);
  pointer-events: none;
  z-index: 0;
  animation: imagineGlow 4s ease-in-out infinite;
}

.imagine-particle-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.imagine-generation-center {
  position: relative;
  z-index: 2;
  width: 100%;
  padding: 34px 20px 16px;
  text-align: center;
  background: linear-gradient(to top, rgba(13, 13, 20, 0.92) 40%, rgba(13, 13, 20, 0));
}

.imagine-generation-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #e8e8ec;
}

.imagine-generation-text {
  margin-top: 4px;
  min-height: 18px;
  font-size: 13px;
  color: #b9b4e6;
  transition: opacity 0.18s ease;
}

.imagine-generation-text.swap {
  opacity: 0;
}

.imagine-generation-progress {
  height: 3px;
  margin-top: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.imagine-generation-progress-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6d5dfc, #a58bff, #e08bff);
  box-shadow: 0 0 10px rgba(165, 139, 255, 0.7);
  transition: width 0.4s linear;
}

@keyframes imagineAppear {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes imagineGlow {
  0%, 100% {
    transform: translate(-50%, -50%) scale(0.9);
    opacity: 0.7;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .imagine-generation-glow {
    animation: none;
  }

  .msg.imagine-generation {
    animation: none;
  }
}

@media (max-width: 700px) {
  .msg.imagine-generation {
    width: 100%;
    max-width: 100%;
    min-height: 250px;
  }
}