* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; background: #07070b; color: #e8e2cf; font-family: 'Courier New', Courier, monospace; }
#game { position: fixed; inset: 0; display: block; cursor: crosshair; image-rendering: pixelated; touch-action: none; }
h1 { font-size: 15px; letter-spacing: 2px; margin: 0 0 8px; color: #ffc629; }
h2 { font-size: 12px; letter-spacing: 2px; margin: 10px 0 6px; color: #b9ae8e; text-transform: uppercase; }
.gold { color: #ffc629; }
.panel { position: fixed; background: rgba(10, 10, 16, 0.86); border: 1px solid #2a2a36; border-radius: 6px; padding: 10px 12px; font-size: 12px; user-select: none; }
.row { display: flex; justify-content: space-between; gap: 16px; line-height: 1.6; }
.row span { color: #8f8a78; }
.row.coins b { color: #ffe27a; font-size: 16px; }

#hud { top: 12px; left: 12px; min-width: 210px; pointer-events: none; }
#hover { margin-top: 6px; min-height: 1.4em; color: #cfe8d4; }
#hint { color: #ffc629; }
#compass-wrap { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: #ffc629; }
#compass-wrap[hidden] { display: none; }
#compass { font-size: 22px; line-height: 1; width: 24px; text-align: center; transition: transform 0.1s linear; }

#side { top: 12px; right: 12px; bottom: 12px; width: 212px; overflow-y: auto; }
#minimap { width: 186px; height: 186px; display: block; border: 1px solid #2a2a36; image-rendering: pixelated; }
#upgrades, #bots { display: flex; flex-direction: column; gap: 5px; }
.shop-item { display: grid; grid-template-columns: 1fr auto; gap: 1px 6px; text-align: left; font: inherit; font-size: 11px; color: inherit; background: #171722; border: 1px solid #33334a; border-radius: 4px; padding: 5px 7px; cursor: pointer; }
.shop-item:hover:not(:disabled) { border-color: #ffc629; }
.shop-item:disabled { opacity: 0.5; cursor: default; }
.shop-item .name { font-weight: bold; color: #f5e6a3; }
.shop-item .lvl { color: #8f8a78; text-align: right; }
.shop-item .desc { color: #8f8a78; grid-column: 1 / -1; }
.shop-item .eff { color: #a9d8b8; }
.shop-item .cost { color: #ffe27a; text-align: right; }
.shop-item.bot .name { color: #4fd1c5; }
#legend { display: grid; gap: 2px; }
.gem-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 6px; align-items: center; font-size: 11px; }
.gem-row i { width: 12px; height: 12px; display: block; }
.gem-row b { color: #b9ae8e; font-weight: normal; }
footer { display: flex; justify-content: space-between; margin-top: 10px; }
.link { background: none; border: none; color: #8f8a78; font: inherit; font-size: 11px; text-decoration: underline; cursor: pointer; padding: 0; }
.link:hover { color: #e8e2cf; }

#toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: #ffc629; color: #1a1406; padding: 6px 14px; border-radius: 4px; font-weight: bold; pointer-events: none; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); display: flex; align-items: center; justify-content: center; z-index: 10; }
.overlay[hidden] { display: none; }
.card { background: #101018; border: 1px solid #ffc629; border-radius: 8px; padding: 24px 28px; max-width: 460px; font-size: 13px; line-height: 1.5; }
.card h1 { font-size: 20px; text-align: center; }
.card ul { padding-left: 18px; }
.card .row { font-size: 14px; }
kbd { display: inline-block; border: 1px solid #555; border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; margin-right: 2px; font-size: 11px; }
.big { display: block; margin: 16px auto 0; font: inherit; font-weight: bold; font-size: 14px; background: #ffc629; color: #1a1406; border: none; border-radius: 4px; padding: 8px 20px; cursor: pointer; }
.big:hover { background: #ffd84a; }

/* --- Touch controls --- */
#joystick, #shop-btn, .mob { display: none; }
.touch .mob { display: list-item; }
.touch .desk { display: none; }
.touch #joystick { display: block; position: fixed; left: calc(24px + env(safe-area-inset-left)); bottom: calc(24px + env(safe-area-inset-bottom)); width: 120px; height: 120px; border-radius: 50%; background: rgba(255, 255, 255, 0.06); border: 2px solid rgba(255, 255, 255, 0.18); touch-action: none; z-index: 5; }
#knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255, 198, 41, 0.55); border: 2px solid rgba(255, 230, 150, 0.8); pointer-events: none; }
#game, #joystick { -webkit-tap-highlight-color: transparent; }

/* --- Small screens: shop becomes a slide-in panel --- */
@media (max-width: 820px) {
  #shop-btn { display: block; position: fixed; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); z-index: 7; font: inherit; font-weight: bold; font-size: 13px; background: #ffc629; color: #1a1406; border: none; border-radius: 4px; padding: 8px 12px; }
  #side { top: 0; right: 0; bottom: 0; width: min(300px, 86vw); border-radius: 0; padding-top: calc(52px + env(safe-area-inset-top)); transform: translateX(100%); transition: transform 0.2s ease; z-index: 6; }
  #side.open { transform: none; }
  #minimap { width: 100%; height: auto; aspect-ratio: 1; }
  .shop-item { padding: 8px; font-size: 12px; }
  #hud { top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); min-width: 0; max-width: 60vw; padding: 6px 8px; font-size: 11px; }
  #hud h1 { font-size: 11px; margin-bottom: 4px; }
  .wide-only { display: none; }
  .card { margin: 12px; padding: 18px; max-height: 90dvh; overflow-y: auto; }
}
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
@media (max-width: 820px) {
  #hover:empty, #hint:empty { display: none; }
}

/* --- Leaderboard --- */
.submit { display: flex; gap: 6px; margin-top: 14px; }
.submit input { flex: 1; min-width: 0; font: inherit; font-size: 14px; background: #171722; color: #e8e2cf; border: 1px solid #33334a; border-radius: 4px; padding: 7px 8px; }
.submit button { font: inherit; font-weight: bold; background: #4fd1c5; color: #06201d; border: none; border-radius: 4px; padding: 7px 10px; cursor: pointer; }
.submit button:disabled { opacity: 0.5; cursor: default; }
#submit-status, #board-status { min-height: 1.2em; margin: 8px 0 0; color: #b9ae8e; text-align: center; }
.actions { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.actions .big { margin: 0; }
#board-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
#board-table th { color: #8f8a78; font-weight: normal; text-align: left; border-bottom: 1px solid #2a2a36; padding: 4px; }
#board-table td { padding: 4px; border-bottom: 1px solid #1a1a24; }
#board-table td:nth-child(3) { color: #ffe27a; }
#board-table tr.me td { background: rgba(255, 198, 41, 0.12); }
#board .card { width: min(460px, 94vw); }
.submit[hidden] { display: none; }

/* --- Shared neufmois.app account --- */
#account { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 11px; color: #b9ae8e; }
#account[hidden], #submit-as[hidden], .submit input[hidden] { display: none; }
#account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#submit-as { flex: 1; align-self: center; color: #b9ae8e; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#submit-as b { color: #f5e6a3; }
.badge { color: #4fd1c5; font-size: 10px; margin-left: 4px; }

/* --- Home --- */
.home { background: radial-gradient(circle at 50% 40%, #16140c 0%, #07070b 70%); }
#home .card { width: min(420px, 94vw); text-align: center; }
#home .card h2 { text-align: left; }
#home-account[hidden], #home-guest[hidden] { display: none; }
#home .link { display: block; margin: 12px auto 0; }
#home footer { justify-content: center; gap: 18px; }
#home footer .link { display: inline; margin: 0; }
.big.alt { background: #33334a; color: #e8e2cf; }
.big.alt:hover { background: #45455f; }
.materials { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 16px; text-align: left; }
#home-current { color: #b9ae8e; min-height: 1.2em; margin: 4px 0 0; }
#home-status { min-height: 1.2em; color: #ff8a8a; }
#home [hidden] { display: none; }
#home-current:empty { display: none; }
#home .note { color: #8f8a78; font-size: 11px; text-align: left; margin: 0 0 6px; }
#home-materials { display: flex; flex-direction: column; gap: 4px; }
.mastery-row { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 8px; align-items: center; font-size: 12px; text-align: left; }
.mastery-row i { width: 12px; height: 12px; display: block; }
.mastery-row .name small { display: block; color: #8f8a78; font-size: 10px; }
.mastery-row b { color: #b9ae8e; font-weight: normal; }
.master-btn { font: inherit; font-size: 11px; background: #171722; color: #ffe27a; border: 1px solid #33334a; border-radius: 4px; padding: 4px 6px; cursor: pointer; min-width: 92px; }
.master-btn:hover:not(:disabled) { border-color: #ffc629; }
.master-btn:disabled { opacity: 0.45; cursor: default; }
#home .card { max-height: 94dvh; overflow-y: auto; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.stat-grid div { background: #171722; border: 1px solid #2a2a36; border-radius: 4px; padding: 6px 4px; }
.stat-grid b { display: block; color: #ffe27a; font-size: 14px; }
.stat-grid span { color: #8f8a78; font-size: 10px; }
#recent-table { width: 100%; border-collapse: collapse; font-size: 11px; text-align: left; }
#recent-table th { color: #8f8a78; font-weight: normal; border-bottom: 1px solid #2a2a36; padding: 3px 4px; }
#recent-table td { padding: 3px 4px; }
#recent-table tr.won td { color: #ffc629; }
#recent-table tr.active td:nth-child(2) { color: #4fd1c5; }
.mastery { color: #ffc629; font-size: 10px; margin-left: 4px; }
@media (max-width: 420px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } #recent-table th:nth-child(5), #recent-table td:nth-child(5) { display: none; } }
