/* ==========================================================================
   Components
   ========================================================================== */

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.625rem 1.125rem;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  transition: all var(--dur-base) var(--ease-out);
  white-space: nowrap;
  user-select: none;
}
.btn:hover:not(:disabled) {
  background: var(--color-surface-3);
  border-color: var(--color-border-hi);
  transform: translateY(-1px);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(135deg, var(--brand-red) 0%, var(--brand-red-hi) 100%);
  color: white;
  border-color: transparent;
  box-shadow: var(--shadow-glow-red);
}
.btn--primary:hover:not(:disabled) {
  box-shadow: 0 0 0 1px rgba(230,51,61,0.5), 0 12px 32px rgba(230,51,61,0.4);
}

.btn--accent {
  background: linear-gradient(135deg, var(--brand-gold) 0%, var(--brand-gold-hi) 100%);
  color: var(--navy-950);
  border-color: transparent;
  box-shadow: var(--shadow-glow-gold);
  font-weight: 600;
}

.btn--teal {
  background: linear-gradient(135deg, var(--brand-teal) 0%, var(--brand-teal-hi) 100%);
  color: var(--navy-950);
  border-color: transparent;
  box-shadow: var(--shadow-glow-teal);
  font-weight: 600;
}

.btn--danger {
  background: transparent;
  border-color: rgba(230,51,61,0.4);
  color: var(--brand-red-hi);
}
.btn--danger:hover:not(:disabled) {
  background: rgba(230,51,61,0.1);
  border-color: var(--brand-red-hi);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}
.btn--ghost:hover:not(:disabled) {
  background: var(--color-surface-2);
  border-color: var(--color-border);
}

.btn--sm { padding: 0.375rem 0.75rem; font-size: var(--fs-xs); }
.btn--lg { padding: 0.875rem 1.5rem; font-size: var(--fs-base); }
.btn--block { width: 100%; }

/* ----- Cards ----- */
.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-md);
}

.card--feature {
  padding: var(--sp-6);
  border-radius: var(--r-xl);
  background:
    linear-gradient(135deg, rgba(56,199,192,0.05) 0%, rgba(255,255,255,0.02) 40%, rgba(230,51,61,0.05) 100%);
  box-shadow: var(--shadow-lg);
}

.card--interactive {
  cursor: pointer;
  transition: all var(--dur-base) var(--ease-out);
}
.card--interactive:hover {
  border-color: var(--color-border-hi);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.card__title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  margin-bottom: var(--sp-2);
}
.card__meta {
  font-size: var(--fs-sm);
  color: var(--color-text-mute);
}

/* ----- Inputs ----- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.field__label {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--color-text-dim);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.field__label .hint {
  color: var(--color-text-mute);
  font-weight: 400;
}

.input, .select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  color: var(--color-text);
  transition: all var(--dur-base) var(--ease-out);
  font-family: var(--font-body);
}
.input::placeholder { color: var(--color-text-mute); }
.input:focus, .select:focus {
  outline: none;
  border-color: var(--brand-teal);
  background: var(--color-surface-2);
  box-shadow: 0 0 0 3px rgba(56,199,192,0.15);
}

.input--mono { font-family: var(--font-mono); }

/* Select options inherit the page background so they look correct in both themes */
.select option {
  background: var(--color-bg);
  color: var(--color-text);
}

.field__error {
  color: var(--color-error);
  font-size: var(--fs-xs);
}

/* ----- Badge ----- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  color: var(--color-text-dim);
  text-transform: uppercase;
  font-family: var(--font-body);
}
.badge__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge--live     { color: var(--color-success); border-color: rgba(58,207,126,0.35); background: rgba(58,207,126,0.1); }
.badge--waiting  { color: var(--brand-gold-hi); border-color: rgba(240,179,42,0.35); background: rgba(240,179,42,0.1); }
.badge--finished { color: var(--navy-300);      border-color: var(--color-border-hi); }
.badge--error    { color: var(--brand-red-hi);  border-color: rgba(230,51,61,0.35);  background: rgba(230,51,61,0.1); }
.badge--full     { color: var(--brand-teal-hi); border-color: rgba(56,199,192,0.35); background: rgba(56,199,192,0.1); }

.badge--live .badge__dot {
  animation: pulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 8px currentColor;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(1.3); }
}

/* ----- Toasts ----- */
.toasts {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 380px;
  padding: var(--sp-4);
  background: rgba(10,15,30,0.85);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--color-border-hi);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  animation: toast-in var(--dur-slow) var(--ease-spring) both;
}

.toast--exit { animation: toast-out var(--dur-base) var(--ease-in-out) forwards; }
.toast__icon { font-size: var(--fs-md); line-height: 1; margin-top: 2px; }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-weight: 600; font-size: var(--fs-sm); margin-bottom: 2px; }
.toast__msg { font-size: var(--fs-xs); color: var(--color-text-dim); }
.toast__close {
  color: var(--color-text-mute);
  padding: 2px;
  font-size: var(--fs-sm);
  line-height: 1;
}
.toast__close:hover { color: var(--color-text); }

.toast--success { border-left: 3px solid var(--color-success); }
.toast--error   { border-left: 3px solid var(--color-error); }
.toast--warn    { border-left: 3px solid var(--color-warn); }
.toast--info    { border-left: 3px solid var(--color-info); }

@keyframes toast-in {
  from { transform: translateX(120%) scale(0.9); opacity: 0; }
  to   { transform: translateX(0) scale(1); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateX(120%) scale(0.9); opacity: 0; }
}

/* ----- Modal ----- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(3,5,10,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  animation: fade-in var(--dur-base) var(--ease-out);
  padding: var(--sp-4);
}

.modal {
  width: 100%;
  max-width: 480px;
  background: rgba(10,15,30,0.95);
  border: 1px solid var(--color-border-hi);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur-slow) var(--ease-spring);
}
.modal__header {
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__title { font-family: var(--font-display); font-size: var(--fs-xl); }
.modal__close {
  color: var(--color-text-mute);
  padding: var(--sp-1);
  font-size: var(--fs-lg);
}
.modal__footer {
  margin-top: var(--sp-6);
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
}

@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ----- Loader ----- */
.loader {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  color: var(--color-text-mute);
  font-size: var(--fs-sm);
}
.loader__spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--color-surface-3);
  border-top-color: var(--brand-teal);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.loader--lg .loader__spinner { width: 32px; height: 32px; border-width: 3px; }
.loader--center {
  padding: var(--sp-10);
  justify-content: center;
  width: 100%;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Turn indicator ----- */
.turn-indicator {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--r-lg);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--glass-border);
  position: relative;
  overflow: hidden;
}
.turn-indicator::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, currentColor 50%, transparent 100%);
  opacity: 0.08;
  animation: sweep 3s linear infinite;
}
.turn-indicator__label {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  color: var(--color-text);
  position: relative;
}
.turn-indicator__who {
  font-weight: 600;
  letter-spacing: 0.01em;
}
.turn-indicator--mine {
  color: var(--brand-teal-hi);
  border-color: rgba(56,199,192,0.35);
  background: rgba(56,199,192,0.08);
}
.turn-indicator--theirs {
  color: var(--brand-gold-hi);
  border-color: rgba(240,179,42,0.3);
  background: rgba(240,179,42,0.05);
}
.turn-indicator--finished {
  color: var(--color-text-mute);
  background: var(--color-surface-2);
}

@keyframes sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ----- Stat pill ----- */
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  min-width: 80px;
}
.stat__label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-mute);
  font-weight: 500;
}
.stat__value {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  color: var(--color-text);
  line-height: 1;
}
.stat__value--sm { font-size: var(--fs-md); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: var(--sp-2);
}

/* ----- Identity (avatar + name) ----- */
.identity {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 12px 4px 4px;
  border-radius: var(--r-pill);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
}
.identity__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-teal) 0%, var(--brand-gold) 100%);
  color: var(--navy-950);
  font-weight: 600;
  font-size: var(--fs-xs);
  display: grid;
  place-items: center;
  letter-spacing: 0;
}
.identity__name {
  font-size: var(--fs-sm);
  font-weight: 500;
}
.identity--lg .identity__avatar { width: 36px; height: 36px; font-size: var(--fs-sm); }
.identity--lg .identity__name { font-size: var(--fs-base); }
.identity--me .identity__avatar {
  background: linear-gradient(135deg, var(--brand-red) 0%, var(--brand-gold) 100%);
}

/* ----- Server pill ----- */
.server-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px 10px 6px 12px;
  border-radius: var(--r-pill);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-text-dim);
  max-width: 260px;
}
.server-pill__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 8px currentColor;
  flex-shrink: 0;
  color: var(--color-success);
}
.server-pill__url {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.server-pill__disconnect {
  color: var(--color-text-mute);
  padding: 2px 4px;
  border-radius: var(--r-sm);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.server-pill__disconnect:hover { color: var(--brand-red-hi); }

/* ----- Move log ----- */
.move-log {
  display: flex;
  flex-direction: column;
  max-height: 400px;
  overflow-y: auto;
}
.move-log__empty {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--color-text-mute);
  font-size: var(--fs-sm);
}
.move-log__item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--fs-sm);
  animation: slide-in var(--dur-base) var(--ease-out);
}
.move-log__item:last-child { border-bottom: 0; }
.move-log__result {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.move-log__result--hit  { background: rgba(230,51,61,0.2); color: var(--brand-red-hi); }
.move-log__result--miss { background: var(--color-surface-3); color: var(--color-text-mute); }
.move-log__detail {
  font-family: var(--font-mono);
  color: var(--color-text-dim);
}
.move-log__detail strong { color: var(--color-text); font-weight: 500; }
.move-log__time {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--color-text-mute);
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ----- Game row in lobby ----- */
.game-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-md);
  transition: all var(--dur-base) var(--ease-out);
}
.game-row:hover {
  border-color: var(--color-border-hi);
  background: var(--color-surface-2);
  transform: translateY(-1px);
}
.game-row__id {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--color-text-mute);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  background: var(--color-surface-3);
}
.game-row__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.game-row__title {
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-row__sub {
  font-size: var(--fs-xs);
  color: var(--color-text-mute);
  font-family: var(--font-mono);
}

/* ----- Placement progress ----- */
.placement-progress {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.placement-progress__label {
  font-size: var(--fs-xs);
  color: var(--color-text-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.placement-progress__dots { display: inline-flex; gap: 4px; }
.placement-progress__dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  transition: all var(--dur-base) var(--ease-spring);
}
.placement-progress__dot--filled {
  background: var(--brand-gold);
  border-color: var(--brand-gold);
  box-shadow: 0 0 8px rgba(240,179,42,0.55);
}

/* ----- Ship list (placement sidebar) ----- */
.ship-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.ship-item {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  opacity: 0.55;
  transition: all var(--dur-base) var(--ease-out);
  position: relative;
}
.ship-item--active  { opacity: 1; border-color: var(--color-border-hi); background: var(--color-surface-2); box-shadow: var(--shadow-sm); }
.ship-item--placed  { opacity: 0.9; }

.ship-item__info { display: flex; align-items: center; gap: var(--sp-2); }
.ship-item__name { font-size: var(--fs-sm); font-weight: 600; letter-spacing: 0.02em; }
.ship-item__name--0 { color: var(--brand-gold-hi); }
.ship-item__name--1 { color: var(--brand-teal-hi); }
.ship-item__name--2 { color: #c084fc; }
.ship-item__size { font-size: var(--fs-xs); color: var(--color-text-mute); font-family: var(--font-mono); margin-left: auto; }

.ship-item__visual { display: flex; gap: 3px; }
.ship-item__cell { width: 14px; height: 14px; border-radius: 3px; border: 1px solid; flex-shrink: 0; }
.ship-item__cell--0 { background: rgba(240,179,42,0.35); border-color: rgba(240,179,42,0.65); }
.ship-item__cell--1 { background: rgba(56,199,192,0.35);  border-color: rgba(56,199,192,0.65); }
.ship-item__cell--2 { background: rgba(167,100,239,0.35); border-color: rgba(167,100,239,0.65); }

.ship-item__remove {
  position: absolute;
  top: var(--sp-2); right: var(--sp-2);
  width: 20px; height: 20px;
  border-radius: var(--r-sm);
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-mute);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all var(--dur-fast) var(--ease-out);
}
.ship-item__remove:hover {
  background: rgba(230,51,61,0.15);
  border-color: rgba(230,51,61,0.5);
  color: var(--brand-red-hi);
}

/* ----- Orientation toggle ----- */
.orientation-toggle { display: flex; flex-direction: column; gap: var(--sp-1); }
.orientation-toggle__label { font-size: var(--fs-xs); color: var(--color-text-mute); text-transform: uppercase; letter-spacing: 0.06em; }
.orientation-toggle__buttons { display: flex; gap: var(--sp-2); }
.orientation-btn {
  flex: 1;
  padding: var(--sp-2);
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  border-radius: var(--r-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-mute);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
.orientation-btn:hover { border-color: var(--color-border-hi); color: var(--color-text); }
.orientation-btn--active {
  background: var(--color-surface-3);
  border-color: var(--brand-teal-hi);
  color: var(--brand-teal-hi);
  box-shadow: 0 0 0 1px rgba(56,199,192,0.25);
}
.orientation-toggle__hint { font-size: var(--fs-xs); color: var(--color-text-mute); opacity: 0.7; }

/* ----- Helper stacks ----- */
.stack    { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row      { display: flex; align-items: center; gap: var(--sp-3); }
.row-sm   { display: flex; align-items: center; gap: var(--sp-2); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.spacer   { flex: 1; }

/* ----- Icon-only button ----- */
.btn--icon { padding: var(--sp-2); width: 32px; height: 32px; flex-shrink: 0; }

/* ----- Theme toggle icon animation ----- */
.theme-toggle__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: theme-icon-in var(--dur-base) var(--ease-spring);
}
@keyframes theme-icon-in {
  from { opacity: 0; transform: rotate(-45deg) scale(0.8); }
  to   { opacity: 1; transform: rotate(0deg)   scale(1); }
}

/* ==========================================================================
   Light mode overrides — only what is meaningfully different
   ========================================================================== */

[data-theme="light"] .toast {
  background: rgba(238,240,248,0.92);
  color: var(--color-text);
}

[data-theme="light"] .modal-backdrop { background: rgba(180,186,219,0.65); }

[data-theme="light"] .modal {
  background: rgba(238,240,248,0.97);
  color: var(--color-text);
}

/* Badges: sufficient contrast on pale backgrounds */
[data-theme="light"] .badge--live     { color: #166534; border-color: rgba(22,101,52,0.40);  background: rgba(22,101,52,0.10); }
[data-theme="light"] .badge--waiting  { color: #92400e; border-color: rgba(146,64,14,0.40);  background: rgba(146,64,14,0.10); }
[data-theme="light"] .badge--finished { color: var(--navy-600); border-color: var(--color-border-hi); }
[data-theme="light"] .badge--error    { color: #b91c1c; border-color: rgba(185,28,28,0.40);  background: rgba(185,28,28,0.10); }
[data-theme="light"] .badge--full     { color: #0f766e; border-color: rgba(15,118,110,0.40); background: rgba(15,118,110,0.10); }