:root{
  --bg:#151220;
  --panel-bg:#221c30;
  --ink:#000;
  --text:#f4efe6;
  --text-dim:#9a8fb0;
  --text-on-dark:#f4efe6;
  --text-dim-on-dark:#9a8fb0;
  --accent:#ffcc00;
  --accent2:#39d1ff;
  --danger:#ff4d4d;
}

/* Buttons, inputs, and canvases keep a fixed dark background in both themes
   (deliberate "dark chrome" look), so their text uses --text-on-dark /
   --text-dim-on-dark instead of the flippable --text / --text-dim below. */
:root[data-theme="light"]{
  --bg:#f2ede4;
  --panel-bg:#ffffff;
  --text:#221c30;
  --text-dim:#6b6478;
  --accent:#9c6f00;
  --accent2:#0077aa;
}

*{box-sizing:border-box}

body{
  margin:0;
  padding:16px 12px 24px;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 3px),
    var(--bg);
  color:var(--text);
  font-family:"Courier New", ui-monospace, Menlo, monospace;
  display:flex;
  justify-content:center;
}

.app{
  width:100%;
  max-width:380px;
}

.title{
  text-align:center;
  font-size:38px;
  font-weight:900;
  letter-spacing:2px;
  margin:0 0 16px;
  color:var(--accent);
  text-shadow:4px 4px 0 #b3001b, 4px 4px 0 #000;
  -webkit-text-stroke:2px #000;
}

.panel{
  background:var(--panel-bg);
  border:3px solid var(--ink);
  border-radius:0;
  padding:8px 12px;
  box-shadow:4px 4px 0 #000;
}

.label{
  font-size:11px;
  letter-spacing:2px;
  color:var(--text-dim);
  text-align:center;
  font-weight:700;
  text-transform:uppercase;
}

.hud-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:14px;
}

.stat-box{
  flex:1;
  text-align:center;
}

.stat-box .value{
  font-size:22px;
  font-weight:800;
  color:var(--accent2);
}

.pause-btn{
  width:46px;
  height:46px;
  background:var(--danger);
  border:3px solid var(--ink);
  color:#000;
  font-size:16px;
  font-weight:900;
  cursor:pointer;
  box-shadow:4px 4px 0 #000;
}

.pause-btn:active{
  transform:translate(4px,4px);
  box-shadow:none;
}

.main-area{
  display:flex;
  gap:12px;
  align-items:flex-start;
}

.board-wrap{
  position:relative;
  flex:1;
  border:4px solid var(--ink);
  box-shadow:4px 4px 0 #000, 0 0 0 3px var(--accent2) inset;
  overflow:hidden;
  line-height:0;
}

#game{
  display:block;
  width:100%;
  height:auto;
  background:#0a0812;
}

.overlay{
  position:absolute;
  inset:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:8px;
  background:rgba(10,8,18,.92);
  cursor:pointer;
}

.overlay.hidden{display:none}

#overlayTitle{
  font-size:24px;
  font-weight:900;
  letter-spacing:2px;
  color:var(--accent);
  text-shadow:3px 3px 0 #000;
}

#overlaySub{
  margin-top:8px;
  font-size:12px;
  color:var(--text-dim-on-dark);
  text-transform:uppercase;
  letter-spacing:1px;
}

.overlay .auth-btn-ghost{
  color:var(--text-dim-on-dark);
  border-color:var(--text-dim-on-dark);
}

.side-panel{
  width:120px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.side-panel canvas{
  display:block;
  width:100%;
  height:auto;
  margin-top:6px;
}

.stats-panel .stat-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-top:8px;
  font-size:12px;
}

.stats-panel .stat-row span:first-child{
  color:var(--text-dim);
  letter-spacing:1px;
  text-transform:uppercase;
}

.stats-panel .stat-row span:last-child{
  font-size:16px;
  font-weight:800;
  color:var(--accent2);
}

.controls{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
  margin-top:16px;
}

.controls button{
  height:44px;
  background:#3a3050;
  border:3px solid var(--ink);
  color:var(--text-on-dark);
  font-size:18px;
  font-weight:900;
  cursor:pointer;
  box-shadow:4px 4px 0 #000;
}

.controls button:active{
  transform:translate(4px,4px);
  box-shadow:none;
}

@media (max-width:400px){
  .title{font-size:32px}
  .side-panel{width:110px}
}

@media (max-width:350px){
  .vs-board-wrap-mine{width:160px}
  .vs-board-wrap-opp{width:120px}
}

.hidden{display:none !important}

.player-row{
  display:flex;
  align-items:center;
  gap:8px;
  margin:-6px 0 14px;
  min-height:20px;
}

.player-row .signout-btn{
  margin-left:auto;
}

.player-name{
  font-size:12px;
  font-weight:800;
  letter-spacing:1px;
  color:var(--accent2);
}

.signout-btn{
  background:none;
  border:none;
  color:var(--text-dim);
  font-family:inherit;
  font-size:11px;
  letter-spacing:1px;
  text-decoration:underline;
  cursor:pointer;
  padding:2px 0;
}

.auth-panel{
  display:flex;
  flex-direction:column;
  gap:12px;
}

.auth-lead{
  margin:4px 0 4px;
  font-size:12px;
  letter-spacing:1px;
  text-align:center;
  color:var(--text-dim);
  text-transform:uppercase;
}

.auth-choice,.auth-form{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.auth-form-title{
  text-align:center;
  font-size:16px;
  font-weight:900;
  letter-spacing:2px;
  color:var(--accent);
  text-shadow:2px 2px 0 #000;
  margin-bottom:2px;
}

.auth-label{
  font-size:11px;
  letter-spacing:1px;
  color:var(--text-dim);
  text-transform:uppercase;
  font-weight:700;
}

.auth-input{
  background:#0a0812;
  border:3px solid var(--ink);
  color:var(--text-on-dark);
  font-family:inherit;
  font-size:15px;
  padding:9px 10px;
  box-shadow:3px 3px 0 #000;
}

.auth-input:focus{
  outline:2px solid var(--accent2);
  outline-offset:1px;
}

.auth-btn{
  height:46px;
  background:#3a3050;
  border:3px solid var(--ink);
  color:var(--text-on-dark);
  font-family:inherit;
  font-size:14px;
  font-weight:900;
  letter-spacing:1px;
  cursor:pointer;
  box-shadow:4px 4px 0 #000;
}

.auth-btn:active{
  transform:translate(4px,4px);
  box-shadow:none;
}

.auth-btn:disabled{
  opacity:.6;
  cursor:default;
}

#signInChoice,#authSubmit{
  background:var(--accent2);
  color:#000;
}

#signUpChoice{
  background:var(--accent);
  color:#000;
}

.auth-btn-ghost{
  background:transparent;
  box-shadow:none;
  border-color:var(--text-dim);
  color:var(--text-dim);
}

.auth-btn-ghost:active{
  transform:none;
}

.auth-error{
  font-size:12px;
  color:var(--danger);
  text-align:center;
  letter-spacing:.5px;
}

.loading-screen{
  position:fixed;
  inset:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:16px;
  background:var(--bg);
}

.loading-studio{
  font-size:18px;
  font-weight:900;
  letter-spacing:2px;
  color:var(--accent);
  text-shadow:3px 3px 0 #000;
  text-align:center;
  padding:0 24px;
  animation:loading-pulse 1.1s steps(2,jump-none) infinite;
}

.loading-text{
  font-size:12px;
  font-weight:700;
  letter-spacing:2px;
  color:var(--text-dim);
  text-transform:uppercase;
}

.loading-dots span{
  animation:loading-dots 1.2s infinite;
  animation-fill-mode:both;
}
.loading-dots span:nth-child(2){animation-delay:.2s}
.loading-dots span:nth-child(3){animation-delay:.4s}

@keyframes loading-pulse{
  0%,100%{opacity:1}
  50%{opacity:.45}
}

@keyframes loading-dots{
  0%,80%,100%{opacity:0}
  40%{opacity:1}
}

.dash-highscore{
  text-align:center;
  font-size:36px;
  font-weight:900;
  color:var(--accent2);
  margin:4px 0 8px;
  text-shadow:3px 3px 0 #000;
}

.dash-coins{
  color:var(--accent);
}

.dash-coins::before{
  content:"\1FA99  ";
}

.vs-code-input{
  text-align:center;
  letter-spacing:6px;
  text-transform:uppercase;
  font-weight:900;
  font-size:20px;
}

div.vs-code-input{
  padding:12px 10px;
  background:#0a0812;
  border:3px solid var(--ink);
  box-shadow:3px 3px 0 #000;
  color:var(--accent);
}

.vs-target-row{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  margin-bottom:12px;
}

.vs-target-row .value{
  font-size:18px;
  font-weight:900;
  color:var(--accent2);
}

.vs-boards{
  display:flex;
  gap:10px;
  justify-content:center;
}

.vs-board-col{
  flex:0 0 auto;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:6px;
}

.vs-board-col .label{
  font-size:10px;
  max-width:100%;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.vs-board-wrap-mine{
  width:190px;
}

.vs-board-wrap-opp{
  width:140px;
}

.vs-board-wrap #vsMyCanvas,
.vs-board-wrap #vsOppCanvas{
  display:block;
  width:100%;
  height:auto;
  background:#0a0812;
}

.vs-mini-score{
  font-size:18px;
  font-weight:800;
  color:var(--accent2);
}

#versusApp .controls{
  max-width:280px;
  margin-left:auto;
  margin-right:auto;
}

#vsResultOverlay{
  gap:20px;
}

#vsResultSub{
  max-width:80%;
  text-align:center;
}

.lb-list{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.lb-row{
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 8px;
  background:#0a0812;
  border:2px solid var(--ink);
  font-size:13px;
  color:var(--text-on-dark);
}

.lb-rank{
  width:22px;
  font-weight:900;
  color:var(--accent);
}

.lb-name{
  flex:1;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  letter-spacing:1px;
}

.lb-score{
  font-weight:900;
  color:var(--accent2);
}

.lb-me{
  border-color:var(--accent);
  box-shadow:2px 2px 0 #000;
}

.lb-me .lb-name{color:var(--accent)}

.lb-sep{
  text-align:center;
  font-size:11px;
  letter-spacing:3px;
  color:var(--text-dim);
}

.lb-status{
  text-align:center;
  font-size:11px;
  letter-spacing:1px;
  color:var(--text-dim);
}

.diff-badge{
  font-size:10px;
  font-weight:800;
  letter-spacing:1px;
  color:var(--accent);
  border:2px solid var(--accent);
  padding:2px 6px;
}

.lb-tabs{
  display:flex;
  gap:6px;
  margin-bottom:6px;
}

.lb-tab{
  flex:1;
  height:32px;
  background:#3a3050;
  border:3px solid var(--ink);
  color:var(--text-dim-on-dark);
  font-family:inherit;
  font-size:10px;
  font-weight:900;
  letter-spacing:1px;
  cursor:pointer;
  box-shadow:3px 3px 0 #000;
}

.lb-tab.active{
  background:var(--accent2);
  color:#000;
}

.lb-tab:active{
  transform:translate(3px,3px);
  box-shadow:none;
}

.imp-wait-players{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin:8px 0;
}

.imp-wait-row{
  background:#0a0812;
  border:2px solid var(--ink);
  padding:8px 10px;
  font-size:13px;
  font-weight:700;
  letter-spacing:1px;
  color:var(--text-on-dark);
}

.imp-timer-row{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  margin-bottom:10px;
}

.imp-timer-row .value{
  font-size:20px;
  font-weight:900;
  color:var(--accent);
}

.imp-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
  justify-content:center;
  margin-bottom:12px;
}

.imp-board-col{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:4px;
}

.imp-board-label{
  font-size:9px;
  max-width:100%;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.imp-board-wrap{
  width:100%;
  max-width:120px;
}

.imp-board-wrap canvas{
  display:block;
  width:100%;
  height:auto;
  background:#0a0812;
}

.imp-col-mine .board-wrap{
  box-shadow:4px 4px 0 #000, 0 0 0 3px var(--accent) inset;
}

.imp-mini-score{
  font-size:13px;
  font-weight:800;
  color:var(--accent2);
}

#imposterApp .controls{
  max-width:280px;
  margin-left:auto;
  margin-right:auto;
}

.imp-sabotage-panel{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-bottom:12px;
}

.imp-sabotage-targets{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
}

.imp-target-btn{
  flex:1;
  min-width:80px;
  height:36px;
  background:#3a3050;
  border:3px solid var(--ink);
  color:var(--text-dim-on-dark);
  font-family:inherit;
  font-size:11px;
  font-weight:900;
  letter-spacing:1px;
  cursor:pointer;
  box-shadow:3px 3px 0 #000;
}

.imp-target-btn.active{
  background:var(--danger);
  color:#000;
}

.imp-target-btn:active{
  transform:translate(3px,3px);
  box-shadow:none;
}

.imp-sabotage-actions{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:6px;
}

.imp-sab-btn{
  height:40px;
  background:#3a3050;
  border:3px solid var(--ink);
  color:var(--text-on-dark);
  font-family:inherit;
  font-size:11px;
  font-weight:900;
  letter-spacing:1px;
  cursor:pointer;
  box-shadow:3px 3px 0 #000;
}

.imp-sab-btn:active:not(:disabled){
  transform:translate(3px,3px);
  box-shadow:none;
}

.imp-sab-btn:disabled{
  opacity:.5;
  cursor:default;
}

.imp-vote-options{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin:8px 0;
}

.imp-vote-btn.active{
  background:var(--accent2);
  color:#000;
}

.icon-btn{
  width:32px;
  height:32px;
  background:#3a3050;
  border:3px solid var(--ink);
  color:var(--text-on-dark);
  font-size:14px;
  line-height:1;
  cursor:pointer;
  box-shadow:3px 3px 0 #000;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:0;
}

.icon-btn:active{
  transform:translate(3px,3px);
  box-shadow:none;
}

.avatar-picker{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:8px;
}

.avatar-preview{
  width:56px;
  height:56px;
  border-radius:50%;
  background:#3a3050;
  border:3px solid var(--ink);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  margin:0 auto;
}

.avatar-preview-lg{
  width:88px;
  height:88px;
}

.avatar-img{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
}

.avatar-initial{
  font-size:22px;
  font-weight:900;
  color:var(--text-on-dark);
}

.avatar-preview-lg .avatar-initial{
  font-size:34px;
}

.setting-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:4px 0;
}

.setting-label{
  font-size:12px;
  font-weight:700;
  letter-spacing:1px;
  color:var(--text);
}

.toggle-switch{
  position:relative;
  display:inline-block;
  width:44px;
  height:24px;
  flex-shrink:0;
}

.toggle-switch input{
  opacity:0;
  width:0;
  height:0;
}

.toggle-slider{
  position:absolute;
  inset:0;
  cursor:pointer;
  background:#3a3050;
  border:2px solid var(--ink);
  transition:background .15s;
}

.toggle-slider::before{
  content:"";
  position:absolute;
  height:16px;
  width:16px;
  left:2px;
  top:2px;
  background:var(--text-on-dark);
  transition:transform .15s;
}

.toggle-switch input:checked + .toggle-slider{
  background:var(--accent2);
}

.toggle-switch input:checked + .toggle-slider::before{
  transform:translateX(20px);
  background:#000;
}

.fps-counter{
  position:fixed;
  top:6px;
  left:6px;
  background:#3a3050;
  color:var(--accent2);
  font-family:"Courier New", ui-monospace, Menlo, monospace;
  font-size:11px;
  font-weight:900;
  padding:3px 6px;
  border:2px solid var(--ink);
  z-index:9999;
  pointer-events:none;
}

.profile-card-name{
  text-align:center;
  font-size:16px;
  font-weight:900;
  letter-spacing:1px;
  color:var(--text);
}

.profile-card-coins{
  text-align:center;
  font-size:13px;
  font-weight:800;
  color:var(--accent);
  margin-bottom:4px;
}

.label-clickable{
  cursor:pointer;
  text-decoration:underline;
}
