* {
  box-sizing: border-box;
}

:root {
  --bg: #080b14;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --text: #f5f7ff;
  --muted: #aab2c8;
  --primary: #7c5cff;
  --primary-2: #25d0ff;
  --danger: #ff4d6d;
  --border: rgba(255, 255, 255, 0.15);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

body {
  margin: 0;
  font-family: Arial, "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 15% 20%, rgba(124, 92, 255, 0.35), transparent 30%),
    radial-gradient(circle at 85% 10%, rgba(37, 208, 255, 0.25), transparent 28%),
    linear-gradient(135deg, #080b14, #11172a 55%, #090d18);
  color: var(--text);
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

.hero {
  position: relative;
  text-align: center;
  padding: 110px 20px 70px;
  overflow: hidden;
}

.hero-glow {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 420px;
  height: 420px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(124, 92, 255, 0.35), transparent 70%);
  filter: blur(10px);
  z-index: -1;
}

.hero h1 {
  margin: 0;
  font-size: clamp(42px, 8vw, 96px);
  letter-spacing: 2px;
  text-shadow: 0 0 30px rgba(124, 92, 255, 0.9);
}

.subtitle {
  margin: 18px 0 32px;
  color: var(--muted);
  font-size: 18px;
}

.hero-btn {
  display: inline-block;
}

.top-nav {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 0;
}

.top-nav a {
  color: var(--muted);
}

.top-nav a:hover {
  color: white;
}

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 36px auto 80px;
}

.panel,
.community-item {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 22px;
  backdrop-filter: blur(18px);
}

.panel {
  padding: 24px;
  margin-bottom: 28px;
}

.hidden {
  display: none !important;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.form-row {
  margin: 18px 0;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #d8ddff;
  font-weight: 700;
}

select,
textarea,
input {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}

select:focus,
textarea:focus,
input:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(37, 208, 255, 0.16);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.code-input {
  min-height: 300px;
  font-family: Consolas, Monaco, monospace;
  line-height: 1.45;
}

.primary-btn,
.secondary-btn,
.danger-btn {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  color: white;
  padding: 13px 22px;
  font-weight: 800;
  transition: transform 0.16s ease, opacity 0.16s ease, box-shadow 0.16s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 28px rgba(124, 92, 255, 0.35);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid var(--border);
}

.danger-btn {
  background: rgba(255, 77, 109, 0.88);
}

.primary-btn:hover,
.secondary-btn:hover,
.danger-btn:hover,
.community-item:hover {
  transform: translateY(-2px);
  opacity: 0.94;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.muted {
  color: var(--muted);
}

.ai-placeholder {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-radius: 18px;
  background: rgba(37, 208, 255, 0.08);
  border: 1px solid rgba(37, 208, 255, 0.22);
  margin: 18px 0;
}

.ai-placeholder p {
  margin: 6px 0 0;
  color: var(--muted);
}

.loader {
  width: 36px;
  height: 36px;
  border: 4px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--primary-2);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.game-frame-wrap {
  height: 700px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
  position: relative;
}

#gameFrame {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

.community-section {
  margin-top: 20px;
}

.community-list {
  display: grid;
  gap: 14px;
}

.community-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 20px;
  cursor: pointer;
  transition: transform 0.16s ease, opacity 0.16s ease;
}

.community-item h3 {
  margin: 0 0 8px;
}

.community-item p {
  margin: 4px 0;
}

.community-badge {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(37, 208, 255, 0.12);
  border: 1px solid rgba(37, 208, 255, 0.3);
  color: #dff8ff;
  white-space: nowrap;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 18px;
}

.share-box {
  margin-bottom: 18px;
}

.rating-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.comments {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.comment-item {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
}

.comment-time {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* ===== 虚拟方向键（移动端适配） ===== */
.dpad-container {
  display: grid;
  grid-template-areas:
    ".    up    ."
    "left .     right"
    ".    down  ."
    "space space space";
  grid-template-columns: 56px 56px 56px;
  grid-template-rows: 56px 56px 56px auto;
  gap: 6px;
  justify-content: center;
  margin-top: 16px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.dpad-btn {
  width: 56px;
  height: 56px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active,
.dpad-active {
  background: rgba(124, 92, 255, 0.7);
  border-color: var(--primary-2);
  transform: scale(0.92);
}

.dpad-up    { grid-area: up; }
.dpad-down  { grid-area: down; }
.dpad-left  { grid-area: left; }
.dpad-right { grid-area: right; }

.dpad-space {
  grid-area: space;
  width: 100%;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: 10px;
  height: 42px;
  margin-top: 4px;
}

/* ===== 流式输出区域 ===== */
.stream-box {
  margin: 18px 0;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  overflow: hidden;
}

.stream-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid var(--border);
}

.stream-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stream-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary-2);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

.stream-stats {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.stream-output {
  padding: 16px 18px;
  max-height: 420px;
  overflow-y: auto;
  font-family: Consolas, Monaco, "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.55;
  color: #c8d6e5;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(0, 0, 0, 0.25);
}

.stream-output::-webkit-scrollbar {
  width: 6px;
}

.stream-output::-webkit-scrollbar-track {
  background: transparent;
}

.stream-output::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.stream-error {
  color: var(--danger);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: rgba(10, 14, 26, 0.92);
  color: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 12px 20px;
  box-shadow: var(--shadow);
  z-index: 99;
}

@media (max-width: 760px) {
  .section-title-row,
  .community-item,
  .rating-row {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: flex-start;
  }

  .community-badge {
    width: fit-content;
  }

  .game-frame-wrap {
    height: 560px;
  }

  .dpad-container {
    grid-template-columns: 50px 50px 50px;
    grid-template-rows: 50px 50px 50px auto;
    gap: 5px;
    margin-top: 14px;
  }

  .dpad-btn {
    width: 50px;
    height: 50px;
    font-size: 20px;
    border-radius: 13px;
  }

  .dpad-space {
    height: 38px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .dpad-container {
    grid-template-columns: 44px 44px 44px;
    grid-template-rows: 44px 44px 44px auto;
    gap: 4px;
    margin-top: 12px;
  }

  .dpad-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
    border-radius: 12px;
  }

  .dpad-space {
    height: 34px;
    font-size: 12px;
  }
}