/* ROGUEBOUND */
:root {
  --bg: #16141f;
  --bg2: #211e2e;
  --panel: #2a2640;
  --line: #4a4468;
  --text: #e8e6f2;
  --dim: #9a94b8;
  --gold: #ffcc46;
  --red: #e84456;
  --green: #5ad469;
  --blue: #5ac8fa;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', ui-monospace, monospace;
  font-weight: bold;
  overflow: hidden;
  image-rendering: pixelated;
}
.hidden { display: none !important; }

.screen { display: none; position: fixed; inset: 0; overflow: auto; }
.screen.active { display: flex; align-items: center; justify-content: center; }

/* ---------------- title */
.title-wrap, .menu-wrap { text-align: center; width: min(560px, 94vw); }
.logo {
  font-size: 56px; letter-spacing: 6px; color: var(--text);
  text-shadow: 0 4px 0 #000, 0 0 24px #6a48d044;
}
.logo span { color: var(--gold); }
.small-logo { font-size: 36px; }
.tagline { color: var(--dim); margin: 8px 0 24px; }
.panel {
  background: var(--panel); border: 2px solid var(--line); border-radius: 8px;
  padding: 20px; margin: 0 auto; box-shadow: 0 8px 0 #00000055;
}
label { color: var(--dim); font-size: 12px; letter-spacing: 2px; }
input {
  background: var(--bg); color: var(--text); border: 2px solid var(--line);
  padding: 10px 12px; font-family: inherit; font-weight: bold; font-size: 16px;
  border-radius: 4px; width: 100%; margin: 6px 0; outline: none; text-transform: none;
}
input:focus { border-color: var(--gold); }
#join-code, #seed-input { text-transform: uppercase; }
.row { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 6px 0; }
.row.center { justify-content: center; }

.btn {
  background: var(--bg2); color: var(--text); border: 2px solid var(--line);
  font-family: inherit; font-weight: bold; font-size: 15px; letter-spacing: 1px;
  padding: 12px 18px; border-radius: 6px; cursor: pointer;
  box-shadow: 0 3px 0 #000a; transition: transform .05s;
  width: 100%;
}
.btn:hover { border-color: var(--gold); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn.small { padding: 8px 12px; font-size: 13px; width: auto; }
.btn.big { font-size: 19px; padding: 16px 22px; }
.btn.gold { background: #4a3a14; border-color: var(--gold); color: var(--gold); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--dim); }
.btn.toggle.active { border-color: var(--gold); color: var(--gold); }
.btn .sub { display: block; font-size: 11px; color: var(--dim); letter-spacing: 0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.hint { color: var(--dim); font-size: 12px; margin-top: 8px; line-height: 1.5; }
.footer-note { color: #565070; font-size: 11px; margin-top: 14px; }

/* ---------------- menu */
.profile-strip { display: flex; gap: 16px; justify-content: center; align-items: center; margin: 10px 0 18px; color: var(--dim); }
.gold-chip { display: inline-flex; gap: 6px; align-items: center; background: #00000044; padding: 4px 10px; border-radius: 12px; color: var(--gold); }
.px16 { width: 16px; height: 16px; }
.menu-grid { display: flex; flex-direction: column; gap: 10px; }
.join-row { display: flex; gap: 8px; }
.join-row input { width: 110px; text-align: center; letter-spacing: 4px; }
.join-row .btn { flex: 1; }

/* ---------------- lobby */
.lobby-wrap { width: min(900px, 96vw); }
.lobby-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.code-box { background: var(--panel); border: 2px solid var(--line); padding: 8px 14px; border-radius: 6px; color: var(--dim); font-size: 13px; }
.code-box b { color: var(--gold); font-size: 22px; letter-spacing: 6px; margin-left: 8px; }
.lobby-cols { display: grid; grid-template-columns: 1fr 1.2fr; gap: 16px; }
.lobby-left, .lobby-right { background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 14px; }
#lobby-players { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; min-height: 180px; }
.pslot {
  display: flex; align-items: center; gap: 10px; background: var(--bg2);
  border: 2px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
.pslot img { width: 40px; height: 40px; image-rendering: pixelated; }
.pslot .pname { flex: 1; }
.pslot .ptag { font-size: 11px; color: var(--dim); }
.pslot.ready { border-color: var(--green); }
.pslot.empty { opacity: .35; justify-content: center; color: var(--dim); }
.pslot .crown { color: var(--gold); }
.mode-box { border-top: 2px dashed var(--line); padding-top: 10px; }
#class-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.class-card {
  background: var(--bg2); border: 2px solid var(--line); border-radius: 8px;
  padding: 10px; cursor: pointer; text-align: center; position: relative;
}
.class-card img { width: 64px; height: 64px; image-rendering: pixelated; }
.class-card.sel { border-color: var(--gold); background: #3a3252; }
.class-card.locked { opacity: .55; }
.class-card .cdesc { font-size: 11px; color: var(--dim); line-height: 1.4; min-height: 44px; }
.class-card .lock { position: absolute; top: 6px; right: 8px; color: var(--gold); font-size: 12px; }
.lobby-actions .btn { flex: 1; }

/* ---------------- game */
#screen-game { background: #0c0a12; flex-direction: column; }
#game-canvas {
  image-rendering: pixelated;
  max-width: 100vw; max-height: 100vh;
  width: auto; height: auto;
  aspect-ratio: 1088 / 704;
}
.overlay {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: #000000a8; z-index: 30;
}
.overlay h2 { color: var(--gold); font-size: 34px; text-shadow: 0 3px 0 #000; margin-bottom: 18px; }
#levelup-cards { display: flex; gap: 14px; }
.lcard {
  width: 190px; background: var(--panel); border: 2px solid var(--line); border-radius: 10px;
  padding: 18px 14px; text-align: center; cursor: pointer; transition: transform .08s;
}
.lcard:hover { transform: translateY(-6px) scale(1.04); border-color: var(--gold); }
.lcard .key { color: var(--dim); font-size: 11px; }
.lcard h3 { color: var(--gold); margin: 6px 0; }
.lcard p { color: var(--text); font-size: 13px; line-height: 1.4; }
.timer-bar { width: 320px; height: 6px; background: #00000088; margin-top: 18px; border-radius: 3px; overflow: hidden; }
#levelup-timer { height: 100%; background: var(--gold); width: 100%; }

#banner {
  position: fixed; top: 16%; left: 50%; transform: translateX(-50%);
  font-size: 30px; color: var(--gold); text-shadow: 0 3px 0 #000, 0 0 30px #ffcc4655;
  letter-spacing: 4px; z-index: 25; pointer-events: none; text-align: center;
}
#itemtoast {
  position: fixed; bottom: 13%; left: 50%; transform: translateX(-50%);
  z-index: 25; pointer-events: none; text-align: center; display: flex; flex-direction: column; gap: 4px;
}
.itoast {
  background: #000000c8; border: 1px solid var(--line); padding: 6px 14px; border-radius: 16px;
  font-size: 13px; animation: fadeup 3.5s forwards;
}
.itoast b { color: var(--gold); }
@keyframes fadeup { 0% { opacity: 0; transform: translateY(10px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------------- results */
.results-wrap { width: min(700px, 95vw); text-align: center; }
#results-title { font-size: 44px; letter-spacing: 6px; text-shadow: 0 4px 0 #000; }
#results-title.win { color: var(--gold); }
#results-title.lose { color: var(--red); }
#results-sub { color: var(--dim); margin: 8px 0 16px; }
#results-table table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
#results-table td, #results-table th { padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 13px; text-align: center; }
#results-table th { color: var(--dim); font-size: 11px; letter-spacing: 1px; }
#results-table .gold-txt { color: var(--gold); }

/* ---------------- modals */
.modal { position: fixed; inset: 0; background: #000000b8; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box {
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px;
  padding: 22px; width: min(720px, 95vw); max-height: 90vh; overflow: auto; text-align: center;
}
.modal-box h2 { color: var(--gold); letter-spacing: 3px; margin-bottom: 12px; }
.modal-box h3 { color: var(--dim); letter-spacing: 2px; margin: 14px 0 8px; font-size: 14px; }
.big-chip { font-size: 18px; margin-bottom: 12px; }
#armory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.meta-card {
  background: var(--bg2); border: 2px solid var(--line); border-radius: 8px; padding: 10px; text-align: left;
}
.meta-card h4 { color: var(--text); font-size: 14px; }
.meta-card p { color: var(--dim); font-size: 11px; margin: 4px 0; line-height: 1.4; }
.pips { display: flex; gap: 3px; margin: 6px 0; }
.pip { width: 14px; height: 8px; background: #00000066; border: 1px solid var(--line); border-radius: 2px; }
.pip.on { background: var(--gold); border-color: var(--gold); }
.meta-card .btn { padding: 7px; font-size: 12px; margin-top: 4px; }
#armory-classes { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#board-table table { width: 100%; border-collapse: collapse; }
#board-table td, #board-table th { padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
#board-table th { color: var(--dim); font-size: 11px; }
#board-table .rank { color: var(--gold); }
.modal-close { margin-top: 16px; width: auto; padding: 10px 30px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; text-align: left; }
.help-cols p { color: var(--dim); font-size: 13px; line-height: 1.6; margin-bottom: 8px; }
.help-cols b { color: var(--text); }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 99; display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.toastmsg {
  background: #2a2640ee; border: 2px solid var(--red); color: var(--text);
  padding: 8px 18px; border-radius: 8px; font-size: 14px; animation: fadeup 3s forwards;
}
.toastmsg.ok { border-color: var(--green); }

@media (max-width: 760px) {
  .lobby-cols, .help-cols { grid-template-columns: 1fr; }
  .logo { font-size: 38px; }
}

/* ============================== touch / mobile */
html, body {
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea { -webkit-user-select: text; user-select: text; }

#touch-layer { position: fixed; inset: 0; z-index: 20; touch-action: none; }
body:not(.touch) #touch-layer, body:not(.touch) #rotate-hint { display: none !important; }

.tstick {
  display: none; position: fixed; width: 132px; height: 132px;
  border: 2px solid rgba(255, 255, 255, 0.25); border-radius: 50%;
  background: rgba(255, 255, 255, 0.06); pointer-events: none; z-index: 21;
}
.tknob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.28);
  border: 2px solid rgba(255, 255, 255, 0.4);
}
.tbtn {
  position: fixed; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 50%;
  background: rgba(42, 38, 64, 0.8); color: var(--text);
  font-weight: bold; z-index: 22; box-shadow: 0 3px 0 #000a;
}
.tbtn.on { background: rgba(74, 58, 20, 0.85); border-color: var(--gold); color: var(--gold); }
#tbtn-dash {
  width: 88px; height: 88px; font-size: 16px; letter-spacing: 1px;
  right: calc(16px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom));
}
#tbtn-act {
  width: 60px; height: 60px; font-size: 22px; color: var(--gold);
  right: calc(118px + env(safe-area-inset-right)); bottom: calc(92px + env(safe-area-inset-bottom));
}
.tbtn.tsmall { width: 44px; height: 44px; font-size: 18px; }
#tbtn-quit { right: calc(12px + env(safe-area-inset-right)); top: calc(10px + env(safe-area-inset-top)); }
#tbtn-fs { right: calc(66px + env(safe-area-inset-right)); top: calc(10px + env(safe-area-inset-top)); }

#rotate-hint {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: rgba(22, 20, 31, 0.96);
  flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 12px;
}
#rotate-hint div { font-size: 64px; color: var(--gold); animation: tilt 2.4s ease-in-out infinite; }
#rotate-hint p { color: var(--dim); line-height: 1.7; }
@keyframes tilt { 0%, 55% { transform: rotate(0); } 75%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) {
  body.touch #screen-game.active #rotate-hint { display: flex; }
}

/* roomier tap targets + scrollable menus on phones */
@media (pointer: coarse) {
  .btn { padding: 14px 18px; }
  .btn.small { padding: 11px 14px; }
  .lcard { width: 150px; padding: 14px 10px; }
  #levelup-cards { gap: 10px; flex-wrap: wrap; justify-content: center; }
  .row { flex-wrap: wrap; }
  .class-card .cdesc { min-height: 0; }
}
@media (max-height: 560px) {
  .screen.active:not(#screen-game) { align-items: flex-start; }
  .title-wrap, .menu-wrap, .lobby-wrap, .results-wrap { margin: 12px auto; }
  .logo { font-size: 30px; }
  .tagline { margin-bottom: 10px; }
}
