/* Virtua-Tennis-inspired Arcade HUD & Modal Drawer */

/* Top Floating HUD Bar */
header{
  position:fixed;
  top:max(6px,env(safe-area-inset-top));
  left:max(10px,env(safe-area-inset-left));
  right:max(10px,env(safe-area-inset-right));
  z-index:30;
  max-width:none;
  margin:0;
  padding:0;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:8px;
  pointer-events:none;
}
.hud-group{
  pointer-events:auto;
  display:flex;
  align-items:center;
  gap:6px;
  background:rgba(11,26,33,0.88);
  border:1px solid #3d606b;
  border-radius:6px;
  padding:4px 10px;
  min-height:34px;
}
.hud-brand{gap:8px;cursor:pointer}
.hud-tag{
  font-size:11px;
  font-weight:800;
  padding:1px 5px;
  border-radius:3px;
  background:#ddbd4e;
  color:#0e2026;
  letter-spacing:0.02em;
}
.hud-tag.rival-tag{
  background:#355661;
  color:#e4f0f2;
}
body.peer-connected .hud-tag.rival-tag{
  background:#1f6f54;
  color:#ffffff;
}
.hud-player-name{
  font-size:13px;
  font-weight:750;
  color:#ffffff;
  white-space:nowrap;
  letter-spacing:0.01em;
}
#hud-status-pill{
  font-size:11px;
  padding:2px 6px;
  border-radius:4px;
  background:#17343e;
  border:1px solid #456873;
  color:#cbe0e2;
  white-space:nowrap;
}
body.peer-connected #hud-status-pill{
  background:#174f3b;
  border-color:#3ca37d;
  color:#e8fff5;
}

.hud-scoreboard{
  position:absolute;
  left:50%;
  transform:translateX(-50%);
  padding:3px 14px;
  gap:10px;
  background:rgba(9,22,28,0.92);
  border:1px solid #567a86;
}
#score{
  font-variant-numeric:tabular-nums;
  font-size:20px;
  font-weight:800;
  min-width:56px;
  text-align:center;
  color:#ffea9f;
  letter-spacing:0.03em;
}
#sets{font-size:12px;font-weight:700;white-space:nowrap;color:#88c6d0}
#sets[hidden]{display:none}

.hud-actions{padding:3px 6px;gap:5px}
.hud-rival-plate{
  display:inline-flex;
  align-items:center;
  gap:5px;
  padding-right:6px;
  border-right:1px solid #35535d;
}
.hud-btn{
  min-height:28px;
  padding:4px 9px;
  font-size:12px;
  font-weight:650;
  border-radius:5px;
  background:#1b3942;
  border:1px solid #4b6d78;
  color:#f5eedb;
  cursor:pointer;
  white-space:nowrap;
}
.hud-btn:hover{background:#244954}
.hud-btn.online-btn{background:#185842;border-color:#3ca37d;color:#f0fff8}
.hud-btn.online-btn:hover{background:#1f6f54}

/* Floating Shot / Serve Feedback Pill */
#intent-feedback{
  position:fixed;
  top:calc(max(6px,env(safe-area-inset-top)) + 40px);
  left:50%;
  transform:translateX(-50%);
  z-index:25;
  pointer-events:none;
  width:auto;
  max-width:min(92vw,500px);
  height:auto;
  margin:0;
  padding:4px 12px;
  text-align:center;
  background:rgba(10,25,31,0.82);
  border:1px solid rgba(86,122,134,0.6);
  border-radius:6px;
  color:#f2cf62;
  transition:opacity 120ms ease;
}
#intent-feedback[data-phase="moving"],
#intent-feedback[data-phase="point"],
#intent-feedback[data-phase="serve-ready"],
#intent-feedback[data-phase="paused"]{
  opacity:0;
  transition:none;
  pointer-events:none;
}
#shot-guide{
  display:block;
  font-size:12px;
  font-weight:650;
  line-height:16px;
  min-height:16px;
  margin:0;
  color:#f2cf62;
}
#shot-guide[data-phase="moving"]{color:#c5d6d7;font-weight:500}
#shot-detail{
  display:block;
  color:#d2e2e3;
  font-size:11px;
  line-height:14px;
  min-height:0;
}
#shot-detail:empty{display:none}
#intent-track{
  height:7px;
  width:190px;
  max-width:65vw;
  position:relative;
  margin:4px auto 2px;
  background:#1d333a;
  border:1px solid #567a86;
  border-radius:3px;
  display:none;
}
#intent-meter{position:absolute;inset:0;background:#9be564;transform:scaleX(0);transform-origin:left}
#intent-feedback[data-sweet="sweet"],#intent-feedback[data-sweet="splash"]{border-color:#1fe866;box-shadow:0 0 12px rgba(31,232,102,0.34)}
#intent-feedback[data-sweet="sweet"] #shot-guide,#intent-feedback[data-sweet="splash"] #shot-guide{color:#6bffa3}
#intent-feedback[data-sweet="sweet"] #intent-meter,#intent-feedback[data-sweet="splash"] #intent-meter{background:linear-gradient(90deg,#15c956,#5dff9c);box-shadow:0 0 8px rgba(31,232,102,0.75)}
#serve-zone{display:none;position:absolute;left:80%;right:0;top:-2px;bottom:-2px;border:1px solid #ffffff;background:rgba(255,234,159,0.25)}
#intent-feedback[data-phase="serve"] #intent-track,
#intent-feedback[data-phase="preparing"] #intent-track{display:block}
#intent-feedback[data-phase="serve"] #serve-zone{display:block}

/* Team Control & Point Messages */
#team-control{
  position:fixed;
  bottom:max(14px,env(safe-area-inset-bottom));
  left:50%;
  transform:translateX(-50%);
  z-index:22;
  pointer-events:none;
  font-size:12px;
  font-weight:600;
  background:rgba(12,29,36,0.85);
  border:1px solid #456873;
  border-radius:5px;
  padding:3px 10px;
  color:#ffda7d;
  white-space:nowrap;
}
#team-control[hidden]{display:none!important}
/* Portrait on a phone (Roger 2026-11-07, doubles): bottom-centre sat on the CONTROL button; it goes above the thumb
   controls (their cluster is ~160 px tall over the bottom inset), and never wider than the screen. */
@media (orientation:portrait) and (pointer:coarse){
  #team-control{bottom:calc(max(14px,env(safe-area-inset-bottom)) + 168px);max-width:calc(100vw - 24px);overflow:hidden;text-overflow:ellipsis}
}

#message[hidden]{display:none}
#message{
  position:absolute;
  top:52px;
  left:50%;
  transform:translateX(-50%);
  z-index:18;
  background:rgba(10,25,31,0.88);
  border:1px solid #567a86;
  padding:4px 12px;
  border-radius:6px;
  font-size:12px;
  font-weight:650;
  max-width:88%;
  text-align:center;
  pointer-events:none;
}
#message[data-finished="true"]{
  top:22%;
  font-size:clamp(16px,2.4vw,24px);
  font-weight:800;
  color:#ffda7d;
  border:1px solid #efc350;
  padding:12px 22px;
  pointer-events:auto;
  cursor:pointer;
}

/* Desktop hover/pointer rules: hide touch controls unless toggled */
@media (hover:hover) and (pointer:fine){
  #controls{display:none}
  body.show-controls #controls{display:flex}
}

/* Portrait & Compact Mobile HUD adjustments (both Portrait and Phone Landscape) */
@media (max-width:900px), (max-height:540px){
  #hud-status-pill,.hud-rival-plate{display:none}
  header{top:max(4px,env(safe-area-inset-top));left:max(8px,env(safe-area-inset-left));right:max(8px,env(safe-area-inset-right));gap:4px}
  .hud-scoreboard{position:static;transform:none;padding:2px 8px}
  .hud-group{padding:2px 7px;min-height:26px;gap:4px}
  .hud-player-name{font-size:11.5px;max-width:92px;overflow:hidden;text-overflow:ellipsis}
  .hud-btn{min-height:24px;padding:2px 7px;font-size:11px}
  #score{font-size:16px;min-width:40px;white-space:nowrap}
  #intent-feedback{top:calc(max(4px,env(safe-area-inset-top)) + 30px);padding:2px 6px;background:transparent;border:none}
  #intent-track{width:130px;height:6px;margin:0 auto}
  #message:not([data-finished="true"]){display:none!important}
}

/* Modal Drawer for Online 1v1, Settings, Tournament, Help & Diagnostics */
#game-modal[hidden]{display:none}
#game-modal{
  position:fixed;
  inset:0;
  z-index:50;
  background:rgba(6,16,20,0.74);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:max(12px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
}
.modal-card{
  width:min(100%,680px);
  max-height:min(90svh,640px);
  background:#112830;
  border:1px solid #3c5d68;
  border-radius:8px;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  color:#f5eedb;
}
.modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 16px;
  background:#0d2027;
  border-bottom:1px solid #2b4750;
}
.modal-header h2{margin:0;font-size:15px;font-weight:700;color:#f5eedb}
.modal-close{
  min-height:32px;
  padding:4px 12px;
  font-size:13px;
  font-weight:600;
  background:#203f47;
  border:1px solid #567680;
  border-radius:5px;
  color:#f5eedb;
  cursor:pointer;
}
.modal-body{
  padding:14px 16px;
  overflow-y:auto;
  display:flex;
  flex-direction:column;
  gap:14px;
  touch-action:pan-y;
  -webkit-overflow-scrolling:touch;
}
.modal-body *{touch-action:manipulation;user-select:text;-webkit-user-select:text}
.modal-section{
  background:#15313b;
  border:1px solid #2d4c57;
  border-radius:6px;
  padding:12px;
}
.modal-section-title{
  margin:0 0 10px;
  font-size:13px;
  font-weight:700;
  color:#e6c775;
}
.settings-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(145px,1fr));
  gap:10px;
}
.field-label{
  display:flex;
  flex-direction:column;
  gap:4px;
  font-size:12px;
  color:#bfd2d4;
}
.field-label select{
  width:100%;
  min-height:36px;
  padding:6px 8px;
  font-size:13px;
  background:#0e2229;
  border:1px solid #4a6b75;
  border-radius:5px;
}
.quick-actions{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:10px;
}
.quick-actions button{
  min-height:36px;
  padding:6px 12px;
  font-size:13px;
  border-radius:5px;
  cursor:pointer;
}
.quick-actions #restart{
  background:#ddbd4e;
  border-color:#f5d982;
  color:#102329;
  font-weight:700;
}

/* Accordion Details inside Modal */
.modal-body details{
  margin:0;
  padding:10px 12px;
  background:#132c35;
  border:1px solid #2b4750;
  border-radius:6px;
}
.modal-body summary{
  cursor:pointer;
  font-size:13px;
  font-weight:600;
  color:#dce8e9;
  min-height:22px;
}
.modal-body details p{
  font-size:13px;
  line-height:1.5;
  margin:8px 0 0;
  color:#c8d8d9;
}
#tournament-panel[hidden]{display:none}
#tournament-panel{border-color:#e6c775}
#next-round{background:#ddbd4e;color:#12262c;font-weight:700;margin-top:8px}
#rulebook a{color:#e6c775}
#diagnostics summary{color:#b8cbcd}

/* Cast View overrides */
body.cast-view #intent-feedback,
body.cast-view #controls,
body.cast-view #team-control{display:none!important}
#cast-note{
  position:fixed;
  bottom:12px;
  left:50%;
  transform:translateX(-50%);
  z-index:25;
  background:rgba(12,29,36,0.9);
  border:1px solid #456873;
  padding:4px 12px;
  border-radius:5px;
  margin:0;
  pointer-events:none;
}
