/* style.css — RedlineStudio look. Dark theme, red accent. */

:root {
  --bg: #0e0f12;
  --bg-panel: #17181d;
  --bg-panel-2: #1e2028;
  --border: #2a2d38;
  --text: #e8e9ee;
  --text-dim: #9aa0ae;
  --red: #e5322d;
  --red-hover: #ff453f;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

a { color: var(--text); text-decoration: none; }
a:hover { color: #fff; }

/* ---------- top nav ---------- */

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-panel);
  border-bottom: 2px solid var(--red);
}

.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 1px;
}
.brand-red { color: var(--red); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.nav-links a { color: var(--text-dim); font-weight: 600; }
.nav-links a:hover { color: #fff; }

.nav-user { display: flex; align-items: center; gap: 12px; }
.nav-username {
  color: #fff;
  font-weight: 700;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- layout ---------- */

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.page-title { font-size: 26px; margin: 8px 0 4px; }
.page-sub { color: var(--text-dim); margin: 0 0 24px; }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-block;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover { background: var(--red-hover); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-small { padding: 6px 14px; font-size: 14px; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--bg-panel-2); color: #fff; }

label { display: block; font-weight: 600; margin: 14px 0 6px; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--red); border-color: var(--red); }

.hint { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

/* ---------- cards / panels ---------- */

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.auth-box { max-width: 380px; margin: 40px auto; }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--bg-panel-2);
  color: var(--text-dim);
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border);
}
.tab.active { background: var(--red); color: #fff; border-color: var(--red); }

/* ---------- games grid ---------- */

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.game-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.1s, border-color 0.1s;
}
.game-card:hover { transform: translateY(-2px); border-color: var(--red); color: var(--text); }

.game-title {
  font-weight: 800;
  font-size: 17px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;         /* long names wrap to two lines… */
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;       /* …and hover shows the full name (title attr) */
}
.game-meta { color: var(--text-dim); font-size: 13px; }
.game-desc {
  color: var(--text-dim);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* the arcade screen on a game card (live or static) */
.card-screen {
  width: 100%;
  display: block;
  border-radius: 8px;
  border: 1px solid #123c24;
  background: #03110a;
  margin-bottom: 4px;
}

.price-badge {
  align-self: flex-start;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.price-badge.paid {
  border-color: #b58900;
  color: #ffd75e;
  background: rgba(255, 215, 94, 0.08);
}

/* studio: game settings + Game/Screen toggle */
.settings-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 16px;
}
.settings-row label { margin-top: 0; }
.settings-row > div { flex: 1; min-width: 160px; }

.seg { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  background: var(--bg-panel-2);
  color: var(--text-dim);
  border: none;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}
.seg-btn.active { background: var(--red); color: #fff; }

.empty-note {
  color: var(--text-dim);
  text-align: center;
  padding: 60px 20px;
}

/* ---------- studio ---------- */

.studio-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 800px) { .studio-layout { grid-template-columns: 1fr; } }

.workspace {
  min-height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  text-align: center;
  padding: 20px;
}

.props-panel h3 { margin-top: 0; }

.my-games { margin-top: 28px; }
.my-game-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

/* ---------- play page ---------- */

.game-frame {
  min-height: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--red);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  white-space: pre-line;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-left-color: #ffb02e; }

/* ---------- studio v1 ---------- */

.page-wide { max-width: 1280px; }

.studio-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.title-input {
  font-size: 20px !important;
  font-weight: 800;
  max-width: 340px;
}
.studio-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.studio-grid {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 230px;
  gap: 14px;
  align-items: start;
}
@media (max-width: 950px) { .studio-grid { grid-template-columns: 1fr; } }

.workspace-canvas {
  width: 100%;
  max-width: 640px;
  display: block;
  margin: 0 auto;
  border: 2px solid #123c24;
  border-radius: 12px;
  background: #03110a;
  box-shadow: 0 0 30px rgba(57, 255, 94, 0.08) inset, 0 0 20px rgba(0,0,0,0.6);
  cursor: crosshair;
  touch-action: none;   /* stops phones scrolling/zooming while playing */
}

/* ---------- game stage: fullscreen + touch controls ---------- */

/* no text-selection, long-press callouts, or tap-flash anywhere in the game area */
.stage, .stage *, .touch-controls, .touch-controls *, .workspace-canvas, .coin-btn {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button, .btn, .tab, .seg-btn, a { -webkit-tap-highlight-color: transparent; }

.stage { position: relative; }
.stage-bar { display: flex; justify-content: center; margin-top: 8px; position: relative; z-index: 10; }

/* attract mode: the "insert coin" overlay on top of the arcade screen */
.attract-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12%;
  background: linear-gradient(transparent 55%, rgba(0, 0, 0, 0.55));
  border-radius: 12px;
}
.coin-btn {
  background: rgba(3, 17, 10, 0.85);
  border: 2px solid #39ff5e;
  color: #8dffa9;
  font-family: "Courier New", monospace;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 1px;
  padding: 14px 26px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(57, 255, 94, 0.35);
  animation: coin-pulse 1.4s ease-in-out infinite;
}
.coin-btn:hover { background: rgba(57, 255, 94, 0.15); }
.coin-btn:disabled { opacity: 0.6; animation: none; }
@keyframes coin-pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(57, 255, 94, 0.25); }
  50% { box-shadow: 0 0 26px rgba(57, 255, 94, 0.6); }
}

/* fullscreen — .fs-on is set by fullscreen.js for BOTH the native API
   and the iOS fallback, so the layout is identical either way */
.stage.fs-on {
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
@supports (height: 100dvh) {
  .stage.fs-on { height: 100dvh; }   /* phones: the REAL visible height, not behind the URL bar */
}
.stage.fs-on .touch-controls {
  flex: 0 0 auto;                    /* controls always keep their space… */
  margin: 0;
  width: 100%;
  max-width: 640px;
}
.stage.fs-on .stage-bar { position: absolute; top: 8px; right: 8px; margin: 0; z-index: 10; }
.stage.fs-fallback {
  position: fixed;
  inset: 0;
  z-index: 300;
}
body.fs-lock { overflow: hidden; }

.stage.fs-on .workspace-canvas {
  /* fill all remaining space; object-fit letterboxes to keep the 4:3 screen */
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: contain;
  border: none;
  border-radius: 0;
}


.touch-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  max-width: 640px;
  margin: 10px auto 0;
  user-select: none;
  -webkit-user-select: none;
}

.touch-dpad {
  display: grid;
  grid-template-areas: ". up ." "left down right";
  gap: 6px;
}
.touch-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.touch-btn {
  min-width: 58px;
  min-height: 58px;
  padding: 8px 14px;
  border-radius: 14px;
  border: 2px solid #1f8f3c;
  background: rgba(57, 255, 94, 0.08);
  color: #8dffa9;
  font-size: 18px;
  font-weight: 800;
  font-family: "Courier New", monospace;
  cursor: pointer;
  touch-action: none;
}
.stage.fs-on .touch-btn { min-width: 50px; min-height: 50px; font-size: 16px; }

.touch-btn.held {
  background: rgba(57, 255, 94, 0.3);
  box-shadow: 0 0 14px rgba(57, 255, 94, 0.5);
}

.explorer h3, .props-panel h3 { margin-top: 0; }
.add-obj-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.obj-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.obj-row:hover { background: var(--bg-panel-2); }
.obj-row.selected { border-color: var(--red); background: var(--bg-panel-2); }
.obj-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.props-panel input[type="number"], .props-panel input[type="text"] { margin-bottom: 4px; }

/* ---------- block editor ---------- */

.blk-event {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid #f5a623;
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 12px;
}
.blk-event-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

.blk {
  border: 1px solid var(--border);
  border-left: 4px solid #4a90d9;
  border-radius: 8px;
  background: var(--bg-panel);
  padding: 6px 8px;
  margin: 6px 0;
}
.blk-set { border-left-color: #4a90d9; }
.blk-change { border-left-color: #7b6cff; }
.blk-if { border-left-color: #f5a623; }
.blk-repeat { border-left-color: #2fbf71; }
.blk-say { border-left-color: #ff5aa5; }
.blk-explode { border-left-color: var(--red); }
.blk-code { border-left-color: #9aa0ae; }

.blk-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.blk-kw { color: var(--text-dim); font-weight: 700; font-size: 13px; }
.blk-else { margin: 4px 0 0 6px; }

.blk-in {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #b9ffcb;
  font-family: "Courier New", monospace;
  font-size: 13px;
  padding: 5px 8px;
  flex: 1;
  min-width: 90px;
  width: auto;
}
.blk-lhs { flex: 0 1 130px; min-width: 70px; }
.blk-in:focus { outline: 1px solid var(--red); }

.blk-body {
  margin: 6px 0 4px 14px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}

.blk-btns { margin-left: auto; display: flex; gap: 4px; }
.blk-mini {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 12px;
}
.blk-mini:hover { color: #fff; border-color: var(--red); }
.blk-del:hover { background: var(--red); }

.blk-add {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 4px;
}
.blk-add-event { font-weight: 700; padding: 8px 10px; }

textarea.blk-code {
  width: 100%;
  margin-top: 6px;
  background: #0a1510;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #b9ffcb;
  font-family: "Courier New", monospace;
  font-size: 13px;
  padding: 10px;
  resize: vertical;
}
textarea.blk-code:focus { outline: 1px solid var(--red); }

code {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 13px;
  color: #b9ffcb;
}

/* ---------- market ---------- */

.market-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.coins-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 800;
  font-size: 17px;
}

/* ---------- player profiles ---------- */

.profile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border-left: 4px solid var(--red);
}
a.nav-username:hover { border-color: var(--red); color: #fff; }

.nav-coins {
  font-weight: 800;
  color: #ffd75e;
  background: rgba(255, 215, 94, 0.08);
  border: 1px solid #b58900;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.nav-coins:hover { color: #fff3c4; border-color: #ffd75e; }


/* ---------- votes ---------- */

.votes { display: inline-flex; gap: 8px; }
.vote-btn {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 5px 14px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}
.vote-btn.up:hover, .vote-btn.up.active { color: #7dff9e; border-color: #2fbf71; background: rgba(57,255,94,0.08); }
.vote-btn.down:hover, .vote-btn.down.active { color: #ff8f8c; border-color: var(--red); background: rgba(229,50,45,0.08); }

/* ---------- comments ---------- */

.comments h3 { margin-bottom: 10px; }
.comment-input { display: flex; gap: 8px; margin-bottom: 12px; }
.comment-input input { flex: 1; }
.comment {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.comment-author { color: #ff8f8c; font-weight: 700; white-space: nowrap; }
.comment-author:hover { color: #fff; }
.comment-text { flex: 1; overflow-wrap: anywhere; }

/* ---------- forums ---------- */

.forum-thread {
  display: block;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
}
.forum-thread:hover { border-color: var(--red); color: var(--text); }
.forum-title { font-weight: 800; font-size: 16px; overflow-wrap: anywhere; }
.forum-post {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
}
.forum-post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.forum-post-head .blk-mini { margin-left: auto; }
.forum-post-body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- guide / about ---------- */

.guide .panel { margin-bottom: 16px; }
.guide h2 { margin-top: 0; }
.codeblock {
  background: #0a1510;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #b9ffcb;
  font-family: "Courier New", monospace;
  font-size: 13px;
  padding: 12px 14px;
  overflow-x: auto;
  white-space: pre;
}
.code {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: "Courier New", monospace;
  font-size: 13px;
  color: #b9ffcb;
}


/* ---------- model snapshot on market cards ---------- */

.model-shot {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  border: 1px solid #123c24;
  background: #03110a;      /* no image = a blank, powered-off screen */
  overflow: hidden;
  margin-bottom: 4px;
}
.model-shot img { width: 100%; height: 100%; display: block; object-fit: cover; }

/* ---------- studio panels: compact, collapsible, floatable ---------- */
/* Side panels scroll inside themselves and stick with you — a packed
   Explorer no longer stretches the page into a giant gap. */
.studio-grid > .panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
}
#obj-list { max-height: 42vh; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
#model-list { max-height: 24vh; overflow-y: auto; }

.panel-head { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.panel-head h3, .panel-head h2 { margin: 0 !important; flex: 1; }
.panel-head .tw { color: var(--text-dim); font-size: 13px; }
.panel-head .drag { cursor: grab; color: var(--text-dim); padding: 0 4px; font-size: 15px; }
.panel-head .drag:hover, .panel-head .dock:hover { color: var(--text); }
.panel-head .dock { cursor: pointer; color: var(--text-dim); padding: 0 4px; font-size: 15px; }
.settings-row .panel-head { flex-basis: 100%; }

.panel.collapsed { max-height: none; }
.panel.collapsed > *:not(.panel-head) { display: none !important; }

.panel.floating {
  position: fixed;
  z-index: 60;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.6);
  border-color: #444;
}
.panel.dragging { opacity: 0.92; }
.float-placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.float-placeholder:hover { color: var(--text); }

@media (max-width: 950px) {
  .studio-grid > .panel { position: static; max-height: none; }
  #obj-list { max-height: 36vh; }
  .panel-head .drag { display: none; }
}
