* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: #0a0a0a;
  color: #eaeaea;
  font-family: "Comic Sans MS", "Comic Neue", cursive, sans-serif;
  font-weight: 700;
  overflow: hidden;
}

button {
  font-family: "Comic Sans MS", "Comic Neue", cursive, sans-serif;
  font-weight: 700;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: "Comic Sans MS", "Comic Neue", cursive, sans-serif;
  font-weight: 700;
  color: #eaeaea;
  background: #171717;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
  outline: none;
}

input:focus {
  border-color: #ffffff;
}

.auth-wrap {
  height: 100vh;
  display: flex;
  align-items: stretch;
  background: #ffffff;
}

.auth-side-left {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 420px;
  padding: 32px;
  background: #ffffff;
}

.auth-side-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 0 64px;
  background: #f0f0f0;
}

.auth-hero-title {
  font-size: 52px;
  line-height: 1.2;
  color: #0a0a0a;
}

.auth-card {
  width: 100%;
  max-width: 340px;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 28px 24px;
}

.logo {
  font-size: 24px;
  text-align: center;
  margin-bottom: 20px;
  color: #0a0a0a;
}

.tabs {
  display: flex;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  padding: 10px 0;
  font-size: 13px;
  color: #888888;
  background: #f5f5f5;
  border-right: 1px solid #e0e0e0;
}

.tab:last-child {
  border-right: none;
}

.tab.active {
  color: #0a0a0a;
  background: #0a0a0a;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

form[hidden] {
  display: none;
}

.auth-wrap label {
  font-size: 12px;
  color: #666666;
  margin-bottom: -6px;
}

.btn-primary {
  margin-top: 6px;
  background: #0a0a0a;
  color: #ffffff;
  font-size: 14px;
  padding: 11px;
  border-radius: 4px;
}

.btn-primary:hover {
  background: #333333;
}

#auth-error {
  min-height: 16px;
  color: #ff5c5c;
  font-size: 12px;
  margin-top: 12px;
  text-align: center;
}

.auth-wrap input {
  color: #0a0a0a;
  background: #ffffff;
  border: 1px solid #d0d0d0;
}

.auth-wrap input:focus {
  border-color: #0a0a0a;
}

.games-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  color: #0a0a0a;
}

.games-page header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  border-bottom: 1px solid #e0e0e0;
  background: #ffffff;
  flex-shrink: 0;
}

.home-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px 24px 12px;
  flex-shrink: 0;
}

.home-avatar-wrap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #e0e0e0;
  flex-shrink: 0;
}

.home-avatar-wrap canvas {
  display: block;
}

.home-greeting {
  font-size: 22px;
  color: #0a0a0a;
}

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

.brand {
  font-size: 17px;
  color: #0a0a0a;
}

.char-header-btn {
  background: #0a0a0a;
  color: #ffffff;
  border-radius: 4px;
  padding: 7px 14px;
  font-size: 12px;
}

.char-header-btn:hover {
  background: #333333;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: #666666;
}

#username-display {
  color: #0a0a0a;
}

.logout-btn {
  border: 1px solid #d0d0d0;
  border-radius: 3px;
  padding: 7px 12px;
  font-size: 12px;
  color: #0a0a0a;
  background: #ffffff;
  text-decoration: none;
  display: inline-block;
}

.logout-btn:hover {
  background: #f5f5f5;
}

.create-btn {
  border: 1px solid #0a0a0a;
  border-radius: 3px;
  padding: 7px 12px;
  font-size: 12px;
  color: #ffffff;
  background: #0a0a0a;
  text-decoration: none;
  display: inline-block;
}

.create-btn:hover {
  background: #333333;
}

main {
  flex: 1;
  padding: 32px 40px;
  overflow-y: auto;
}

main h1 {
  font-size: 24px;
  margin-bottom: 24px;
  color: #0a0a0a;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  max-width: 900px;
}

.game-card {
  position: relative;
  background: #ffffff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.game-card:hover {
  border-color: #0a0a0a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.game-card-link {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.thumb {
  position: relative;
  height: 130px;
  background: linear-gradient(
    180deg,
    #cfe9ff 0%,
    #cfe9ff 55%,
    #9a9a9a 55%,
    #9a9a9a 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.thumb-title {
  max-width: 100%;
  text-align: center;
  font-size: 20px;
  line-height: 1.2;
  color: #0a0a0a;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.35);
  overflow-wrap: break-word;
  word-break: break-word;
}

.edit-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #ffffff;
  color: #0a0a0a;
  border-radius: 3px;
  padding: 5px 10px;
  font-size: 11px;
  text-decoration: none;
  z-index: 5;
}

.edit-btn:hover {
  background: #dddddd;
}

.game-info {
  padding: 12px 14px;
}

.game-title {
  font-size: 15px;
  color: #0a0a0a;
}

.game-meta {
  font-size: 11px;
  color: #888888;
  margin-top: 4px;
}

.char-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
}

.char-modal.open {
  display: flex;
}

.char-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.char-modal-box {
  position: relative;
  margin: auto;
  background: #ffffff;
  border-radius: 8px;
  width: 680px;
  max-width: 95vw;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.char-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
}

.char-modal-header span {
  font-size: 16px;
  color: #0a0a0a;
}

.char-close-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: none;
  border: none;
  cursor: pointer;
}

.char-close-btn:hover {
  background: #f0f0f0;
}

.char-close-btn img {
  width: 14px;
  height: 14px;
}

.char-modal-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.char-preview {
  flex: 1;
  min-height: 400px;
  background: #8fd0ff;
  position: relative;
}

.char-preview canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.char-colors {
  width: 240px;
  flex-shrink: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-left: 1px solid #e0e0e0;
  overflow-y: auto;
}

.char-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.char-color-row label {
  font-size: 12px;
  color: #666666;
  width: 70px;
  flex-shrink: 0;
}

.char-color-picker {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  background: none;
}

.char-hex-input {
  flex: 1;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  color: #0a0a0a;
  background: #ffffff;
  font-family: monospace;
}

.char-hex-input:focus {
  border-color: #0a0a0a;
  outline: none;
}

.char-save-btn {
  margin-top: auto;
  background: #0a0a0a;
  color: #ffffff;
  padding: 10px;
  border-radius: 4px;
  border: none;
  font-size: 13px;
  cursor: pointer;
  font-family: "Comic Sans MS", "Comic Neue", cursive, sans-serif;
  font-weight: 700;
}

.char-save-btn:hover {
  background: #333333;
}

.game-wrap {
  position: relative;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  background: #000;
  font-family: "Comic Sans MS", "Comic Sans", "Comic Neue", cursive, sans-serif;
}

.game-wrap * {
  font-family: "Comic Sans MS", "Comic Sans", "Comic Neue", cursive, sans-serif;
}

.game-wrap button,
.game-wrap input,
.game-wrap label,
.game-wrap a {
  font-family: "Comic Sans MS", "Comic Sans", "Comic Neue", cursive, sans-serif;
  font-weight: 700;
}

#game-canvas,
#studio-canvas {
  display: block;
  width: 100%;
  height: 100%;
  filter: none;
  transition: filter 0.25s ease;
  touch-action: none;
}

#game-canvas.blurred {
  filter: blur(10px);
}

#top-left-controls {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  gap: 10px;
  z-index: 20;
}

#gear-btn,
#chat-btn {
  width: 40px;
  height: 40px;
  background: #ffffff;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gear-btn img,
#chat-btn img {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

#settings-panel,
#chat-panel {
  position: absolute;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 12px;
  display: none;
  flex-direction: column;
  gap: 12px;
  z-index: 20;
}

#settings-panel.open,
#chat-panel.open {
  display: flex;
}

#settings-panel {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
}

.panel-title {
  font-size: 13px;
  color: #ffffff;
  margin-bottom: 4px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #ffffff;
}

.panel-close {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}

.panel-close img {
  width: 14px;
  height: 14px;
  pointer-events: none;
}

.panel-close:hover {
  background: rgba(255, 255, 255, 0.15);
}

#leave-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #ffffff;
  color: #0a0a0a;
  border: 2px solid #ffffff;
  border-radius: 4px;
  padding: 10px 12px;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
}

#leave-btn img {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

#leave-btn:hover {
  background: #e0e0e0;
  border-color: #e0e0e0;
}

#fullscreen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #ffffff;
  color: #0a0a0a;
  border: 2px solid #ffffff;
  border-radius: 4px;
  padding: 10px 12px;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
}

#fullscreen-btn:hover {
  background: #e0e0e0;
  border-color: #e0e0e0;
}

.fov-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fov-control label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #ffffff;
  margin-bottom: 0;
}

.fov-control label img {
  width: 15px;
  height: 15px;
  pointer-events: none;
}

.fov-control label span:first-of-type {
  flex: 1;
}

#fov-value {
  color: #ffffff;
}

#fov-slider {
  width: 100%;
  accent-color: #ffffff;
}

#chat-panel {
  top: 64px;
  left: 16px;
  width: 260px;
  height: 260px;
  background: rgba(10, 10, 10, 0.92);
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
}

.chat-message {
  background: #171717;
  border: 1px solid #2a2a2a;
  border-radius: 3px;
  padding: 6px 8px;
  color: #ffffff;
  word-break: break-word;
}

.chat-input-row {
  display: flex;
  gap: 6px;
}

.chat-input-row input {
  padding: 8px 10px;
  font-size: 12px;
  background: #171717;
  border: 1px solid #2a2a2a;
  color: #ffffff;
}

#chat-send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: #ffffff;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#chat-send-btn img {
  width: 17px;
  height: 17px;
  pointer-events: none;
}

#health-bar-container {
  position: absolute;
  left: 24px;
  bottom: 176px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#health-bar-container img {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

#health-bar-track {
  width: 160px;
  height: 14px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  overflow: hidden;
}

#health-bar-fill {
  height: 100%;
  width: 100%;
  background: #39d353;
  transition: width 0.15s linear;
}

#joystick-base {
  position: absolute;
  left: max(24px, calc(env(safe-area-inset-left) + 16px));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.85);
  border: 6px solid rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  z-index: 15;
}

#joystick-base img {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

#joystick-handle {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.9);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  touch-action: none;
}

#cam-joystick-base {
  position: absolute;
  right: max(24px, calc(env(safe-area-inset-right) + 16px));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.85);
  border: 6px solid rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  z-index: 15;
}

#cam-joystick-base img {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

#cam-joystick-handle {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.9);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  touch-action: none;
}

#jump-btn {
  position: absolute;
  right: max(46px, calc(env(safe-area-inset-right) + 32px));
  bottom: calc(max(24px, calc(env(safe-area-inset-bottom) + 16px)) + 160px);
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #0a0a0a;
  border: 3px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  z-index: 15;
}

.jump-icon {
  width: 26px;
  height: 26px;
  pointer-events: none;
}

#jump-btn:active {
  background: #2a2a2a;
}

#joystick-handle.active,
#cam-joystick-handle.active {
  background: #dddddd;
}

body.desktop-mode .mobile-control {
  display: none !important;
}

body.desktop-mode #health-bar-container {
  bottom: 24px;
  left: 24px;
}

#player-list {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  padding: 10px 12px;
  min-width: 120px;
  max-width: 200px;
  z-index: 20;
}

#player-list-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-list-item {
  color: #ffffff;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#studio-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  z-index: 20;
}

.studio-game-name {
  color: #ffffff;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  padding: 8px 12px;
  margin-right: auto;
}

.studio-btn {
  background: rgba(0, 0, 0, 0.55);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  padding: 9px 16px;
  font-size: 13px;
  text-decoration: none;
  display: inline-block;
}

.studio-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.studio-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
}

.studio-btn-primary {
  background: #39d353;
  color: #0a0a0a;
  border-color: #39d353;
}

.studio-btn-leave {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.9);
  color: #0a0a0a;
}

.studio-btn-leave:hover {
  background: #ffffff;
}

.studio-btn-danger {
  background: rgba(255, 50, 50, 0.2);
  border-color: rgba(255, 50, 50, 0.4);
  color: #ff9d9d;
}

.studio-btn-danger:hover {
  background: rgba(255, 50, 50, 0.35);
}

.studio-btn-danger.active {
  background: #ff4d4d;
  border-color: #ff4d4d;
  color: #0a0a0a;
}

#studio-status {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 3px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

#studio-status.visible {
  opacity: 1;
}

#explorer-panel {
  position: absolute;
  top: 56px;
  left: 16px;
  width: 200px;
  max-height: calc(100vh - 280px);
  background: rgba(20, 20, 20, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.explorer-header {
  padding: 8px 12px;
  font-size: 12px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

#explorer-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.explorer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: #cccccc;
  cursor: pointer;
  user-select: none;
}

.explorer-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.explorer-item.selected {
  background: rgba(59, 130, 246, 0.35);
  color: #ffffff;
}

.explorer-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.explorer-script-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

#script-editor-panel {
  position: absolute;
  top: 56px;
  left: 232px;
  width: 480px;
  height: calc(100vh - 120px);
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  z-index: 25;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

#script-editor-panel.open {
  display: flex;
}

.script-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

#script-editor-title {
  font-size: 13px;
  color: #0a0a0a;
}

.script-editor-close-btn {
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: #666666;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}

.script-editor-close-btn:hover {
  background: #e0e0e0;
  color: #0a0a0a;
}

#script-editor-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 12px;
  font-family: "Courier New", Courier, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #0a0a0a;
  background: #ffffff;
  tab-size: 2;
}

#studio-console {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: 180px;
  background: rgba(10, 10, 10, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.studio-console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.studio-console-header span {
  font-size: 11px;
  color: #aaaaaa;
}

#studio-console-clear {
  font-size: 10px;
  color: #888888;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 2px;
  padding: 2px 8px;
  cursor: pointer;
}

#studio-console-clear:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

#studio-console-output {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #cccccc;
}

#studio-console-output div {
  word-break: break-all;
}
