* { box-sizing: border-box; }

html {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: #f0f9ff;
  color: #1a1d27;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  touch-action: pan-y;
}

body {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  background: #f0f9ff;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #ffffff;
  border-bottom: 1px solid rgba(0,0,0,0.07);
  padding: 14px 18px 10px;
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-title {
  font-size: 20px;
  font-weight: 900;
  margin: 0;
  letter-spacing: -0.3px;
  color: #1a1d27;
}

.topbar-role {
  font-size: 11px;
  font-weight: 700;
  color: #0284c7;
  background: #e0f2fe;
  padding: 2px 8px;
  border-radius: 8px;
}

.topbar-room-code {
  font-size: 13px;
  font-weight: 800;
  color: #8a92a6;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.topbar-install-btn {
  min-height: 36px;
  min-width: 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  font-size: 18px;
  background: #e0f2fe;
  color: #0284c7;
  flex-shrink: 0;
}

/* ── Content ── */
.content {
  flex: 1;
  padding: 16px 14px 160px;
  touch-action: pan-y;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

/* ── Cards ── */
.card {
  background: #ffffff;
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  border: 1px solid rgba(0,0,0,0.04);
}

.card h3 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  color: #1a1d27;
  letter-spacing: -0.2px;
}

.hidden-admin {
  display: none !important;
}

/* ── Form controls ── */
input, select {
  width: 100%;
  min-height: 46px;
  font-size: 16px;
  padding: 10px 14px;
  margin: 0;
  border-radius: 14px;
  border: 1.5px solid #e2e6ef;
  background: #f8f9fc;
  color: #1a1d27;
  transition: border-color 0.15s;
  outline: none;
}

input:focus, select:focus {
  border-color: #0ea5e9;
  background: #fff;
}

/* ── Buttons ── */
button {
  border: none;
  border-radius: 14px;
  min-height: 46px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: #0ea5e9;
  color: white;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s, transform 0.1s;
  letter-spacing: -0.1px;
}

button:active {
  opacity: 0.82;
  transform: scale(0.985);
}

button.secondary {
  background: #e0f2fe;
  color: #0284c7;
}

button.gray {
  background: #eceef3;
  color: #4a5066;
}

button.danger-btn {
  background: #e53535;
  color: white;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* ── Grid layouts ── */
.btn-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-grid-1 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.input-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ── Player grid ── */
.player-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.player-grid input {
  text-align: center;
  padding-left: 6px;
  padding-right: 6px;
}

/* ── Typography ── */
.small {
  font-size: 12px;
  color: #8a92a6;
  line-height: 1.5;
}

/* ── Match cards ── */
.match {
  border: 1.5px solid #e2e6ef;
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 10px;
  background: #f8f9fc;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.match.done {
  background: #f0faf3;
  border-color: #7ecb96;
}

.winnerText {
  color: #1a9e4a;
  font-weight: 800;
  margin-top: 6px;
  font-size: 14px;
}

.danger {
  color: #e53535;
  font-weight: 700;
}

/* ── Badges ── */
.room-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 3px 8px;
  border-radius: 20px;
  background: #e0f2fe;
  color: #0284c7;
  font-size: 11px;
  font-weight: 700;
}

.courtBadge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  background: #bae6fd;
  color: #0369a1;
  border-radius: 20px;
  padding: 4px 10px;
  margin-bottom: 8px;
}

/* ── Status box ── */
.status-box {
  padding: 12px 14px;
  border-radius: 14px;
  background: #f4f6fb;
  border: 1px solid #e2e6ef;
  line-height: 1.6;
}

/* ── Floating room status ── */
.floating-room-status {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  z-index: 60;
  display: none;
  align-items: center;
  gap: 8px;
  border-radius: 0 0 16px 16px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: rgba(20, 24, 40, 0.97);
  color: white;
  font-size: 12px;
  font-weight: 700;
  width: 100%;
  max-width: 480px;
  justify-content: center;
  letter-spacing: 0.1px;
}

.floating-room-status.show {
  display: flex;
}

/* ── Status dot ── */
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.status-dot.connected {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34,197,94,0.25);
}

.status-dot.disconnected {
  background: #f05252;
  box-shadow: 0 0 0 3px rgba(240,82,82,0.25);
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 32px;
  width: 100%;
  max-width: 480px;
  background: #ffffff;
  border-top: 1px solid rgba(0,0,0,0.07);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 70;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.nav-btn {
  background: transparent;
  color: #9aa0b4;
  min-height: 54px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 2px;
  transition: color 0.15s, background 0.15s;
}

.nav-btn.active {
  background: #e0f2fe;
  color: #0284c7;
  font-weight: 800;
}

/* ── Record Table (경기 기록) ── */
.record-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.record-table th {
  padding: 8px 4px;
  text-align: center;
  border: 1px solid #d1d5db;
  background: #f3f4f6;
  font-weight: 700;
  color: #374151;
}
.record-table td {
  padding: 10px 4px;
  text-align: center;
  border: 1px solid #d1d5db;
}
.record-table td:first-child {
  text-align: center;
  font-weight: 500;
}
.record-table tr.eliminated td {
  color: #9ca3af;
}

/* ── History ── */
.history-box {
  max-height: 360px;
  overflow: auto;
  line-height: 1.6;
  word-break: break-word;
  font-size: 13px;
  color: #374151;
}
.hist-round {
  margin-bottom: 18px;
  text-align: center;
}
.hist-round-header {
  font-weight: 700;
  font-size: 14px;
  color: #0284c7;
  margin-bottom: 4px;
}
.hist-match {
  font-size: 13px;
  line-height: 2;
  color: #1f2937;
}
.hist-match b {
  font-weight: 800;
}
.hist-handicap {
  font-size: 12px;
  color: #9ca3af;
  line-height: 2;
}
.hist-waiting-wrap {
  margin-top: 22px;
  display: flex;
  justify-content: center;
}
.hist-waiting-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #9ca3af;
  border-radius: 12px;
  padding: 14px 20px 10px;
  position: relative;
  min-width: 100px;
  min-height: 48px;
}
.hist-waiting-label {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  color: #374151;
  border: 1.5px solid #9ca3af;
  border-radius: 4px;
  white-space: nowrap;
}
.hist-waiting-players {
  font-size: 13px;
  color: #374151;
}

/* ── Splash ── */
.splash {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #0ea5e9, #0284c7);
  color: white;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: opacity 0.4s ease;
}

.splash.hide {
  opacity: 0;
  pointer-events: none;
}

.splash-logo-full {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.splash-logo-full img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hidden-host {
  display: none !important;
}

/* ── Player slot cards ── */
.hidden-player-inputs { display:none; }

.player-slot-card {
  min-height: 58px;
  border: 1.5px dashed #d0d6e8;
  border-radius: 14px;
  background: #f8f9fc;
  color: #1a1d27;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px 8px;
  transition: background 0.15s, border-color 0.15s;
}

.player-slot-card.filled {
  border-style: solid;
  background: #e0f2fe;
  border-color: #7dd3fc;
}

.player-slot-card .player-slot-label {
  display: block;
  font-size: 11px;
  color: #9aa0b4;
  margin-bottom: 2px;
  width: 100%;
}

.player-slot-card .player-slot-name {
  display: block;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.player-slot-card.filled .player-slot-label {
  display: none;
}

/* ── Player modal ── */
.player-modal.hidden { display: none; }

.player-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.player-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,14,30,0.5);
}

.player-modal-sheet {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 46%;
  bottom: auto;
  transform: translateY(-46%);
  max-width: 520px;
  margin: 0 auto;
  background: #fff;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.2);
}

.player-modal-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 14px;
  letter-spacing: -0.2px;
}

.player-modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-modal-body input {
  font-size: 18px;
}

.player-modal-name {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  padding: 14px 10px;
  border-radius: 14px;
  background: #f4f6fb;
  margin-top: 4px;
}

.player-modal-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.player-modal-actions.single {
  grid-template-columns: 1fr 1fr;
}

/* ── Galge display ── */
.galge-super-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1.5px solid #fcd34d;
  border-radius: 16px;
  padding: 16px 12px 12px;
  margin-bottom: 12px;
  gap: 4px;
}

.galge-crown {
  font-size: 28px;
  line-height: 1;
  margin-bottom: 2px;
}

.galge-super-name {
  font-size: 20px;
  font-weight: 900;
  color: #92400e;
  letter-spacing: -0.3px;
}

.galge-super-label {
  font-size: 11px;
  font-weight: 700;
  color: #b45309;
  background: #fde68a;
  border-radius: 20px;
  padding: 2px 10px;
  margin-top: 2px;
  letter-spacing: 0.3px;
}

.galge-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.galge-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #f4f6fb;
  border: 1px solid #e2e6ef;
  border-radius: 20px;
  padding: 5px 10px 5px 10px;
}

.galge-badge-name {
  font-size: 13px;
  font-weight: 700;
  color: #1a1d27;
}

.galge-badge-round {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #6b7280;
  border-radius: 10px;
  padding: 1px 6px;
}

/* ── Records modals ── */
.records-modal { position: fixed; inset: 0; z-index: 500; }
.records-modal.hidden { display: none; }

.records-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10,14,30,0.55);
}

.records-modal-sheet {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  max-width: 520px;
  margin: 0 auto;
  background: #fff;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.22);
  max-height: 80dvh;
  overflow-y: auto;
  z-index: 1;
}

.records-modal-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 14px;
  letter-spacing: -0.2px;
}

.records-modal-body {
  margin-bottom: 0;
}

.records-modal-actions { margin-top: 14px; }

.records-list-container { margin-bottom: 4px; }

.record-list-item {
  padding: 13px 14px;
  border-radius: 14px;
  background: #f4f6fb;
  border: 1px solid #e2e6ef;
  margin-bottom: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  transition: background 0.13s;
}
.record-list-item:active { background: #e1e6f5; }

/* Full-screen record detail */
.records-detail-modal { position: fixed; inset: 0; z-index: 500; background: #f0f9ff; display: flex; flex-direction: column; }
.records-detail-modal.hidden { display: none; }

.records-detail-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.records-detail-header {
  padding: 16px 18px 8px;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,0.07);
  flex-shrink: 0;
}

.records-detail-title {
  font-size: 20px;
  font-weight: 900;
  color: #1a1d27;
  letter-spacing: -0.3px;
}

.records-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 10px;
}

.records-detail-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid rgba(0,0,0,0.07);
  flex-shrink: 0;
  gap: 10px;
}

.records-detail-room-btn {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 10px;
  white-space: nowrap;
}

/* ── Room list ── */
.room-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f4f6fb;
  border: 1px solid #e2e6ef;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.13s;
}
.room-list-item:active { background: #e1e6f5; }
.room-list-item-current {
  background: #e0f2fe;
  border-color: #7dd3fc;
}
.room-list-code {
  font-weight: 800;
  font-size: 15px;
  color: #1a1d27;
  flex-shrink: 0;
}
.room-list-meta {
  font-size: 12px;
  color: #8a92a6;
  flex: 1;
}
.room-list-badge {
  font-size: 11px;
  font-weight: 700;
  background: #0ea5e9;
  color: #fff;
  border-radius: 20px;
  padding: 2px 8px;
  flex-shrink: 0;
}
.room-list-delete-btn {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 15px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.13s;
}
.room-list-delete-btn:active { background: #fee2e2; }

/* ── Responsive ── */
@media (max-width: 420px) {
  .player-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .bottom-nav {
    row-gap: 4px;
  }

  .floating-room-status {
    bottom: 0;
  }
}
