/* ==========================================================================
   Go 3D — UI components
   ========================================================================== */

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */

.nav {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.nav[data-scrolled='true'] {
  border-bottom-color: var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}

.nav .wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 640;
  letter-spacing: -0.02em;
  font-size: 1.02rem;
  margin-right: 8px;
  flex: 0 0 auto;
}

.brand-mark {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
}

.nav-link {
  padding: 7px 12px;
  border-radius: var(--r-full);
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
}
.nav-link[aria-current='page'] {
  color: var(--text);
  background: var(--surface-2);
}

.nav-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  border: 1px solid var(--line);
}

@media (max-width: 860px) {
  .nav-toggle {
    display: inline-flex;
  }
  .nav-links {
    position: fixed;
    inset: var(--nav-h) 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 12px var(--gutter) 20px;
    background: color-mix(in srgb, var(--bg) 96%, transparent);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--line);
    transform-origin: top;
    display: none;
  }
  .nav-links[data-open='true'] {
    display: flex;
    animation: sheet-in var(--dur) var(--ease);
  }
  .nav-link {
    padding: 12px 14px;
    border-radius: var(--r-sm);
    font-size: 1rem;
  }
  .nav-actions {
    margin-left: auto;
  }
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: var(--line-strong);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  min-height: 40px;
  border-radius: var(--r-full);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 0.9rem;
  font-weight: 560;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--line-strong);
}
.btn:active:not(:disabled) {
  transform: scale(0.975);
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  --btn-bg: var(--jade);
  --btn-fg: #04150d;
  --btn-border: transparent;
  font-weight: 640;
  box-shadow: 0 6px 24px -10px rgba(61, 220, 151, 0.7);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--jade) 88%, white);
  box-shadow: 0 8px 30px -8px rgba(61, 220, 151, 0.8);
}

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

.btn-outline {
  --btn-bg: transparent;
  --btn-border: var(--line-strong);
}

.btn-danger {
  --btn-bg: var(--clay-soft);
  --btn-fg: var(--clay);
  --btn-border: color-mix(in srgb, var(--clay) 35%, transparent);
}
.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--clay) 22%, transparent);
}

.btn-lg {
  min-height: 50px;
  padding: 14px 28px;
  font-size: 1rem;
}
.btn-sm {
  min-height: 32px;
  padding: 6px 12px;
  font-size: 0.82rem;
}
.btn-icon {
  width: 40px;
  padding: 0;
  flex: 0 0 auto;
}
.btn-icon.btn-sm {
  width: 32px;
}
.btn-block {
  width: 100%;
}

.btn .spinner {
  width: 15px;
  height: 15px;
}

/* --------------------------------------------------------------------------
   Surfaces
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
}

.panel {
  background: var(--surface-glass);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 620;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.panel-body {
  padding: 14px;
}

.divider {
  height: 1px;
  background: var(--line);
  border: 0;
  margin: 14px 0;
}

/* --------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.label {
  font-size: 0.78rem;
  font-weight: 580;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.45;
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 10px 13px;
  min-height: 40px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 0.92rem;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--jade);
  background: var(--surface-3);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%23a3adbd' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
  cursor: pointer;
}
.select option {
  background: var(--surface-2);
  color: var(--text);
}

.textarea {
  min-height: 76px;
  resize: vertical;
}

/* Segmented control — used for board size, difficulty, rules, 2D/3D. */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
}

.segmented > button {
  padding: 6px 14px;
  border-radius: var(--r-full);
  font-size: 0.84rem;
  font-weight: 560;
  color: var(--text-dim);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.segmented > button:hover {
  color: var(--text);
}
.segmented > button[aria-pressed='true'] {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.segmented.is-block {
  display: flex;
}
.segmented.is-block > button {
  flex: 1;
}

/* Switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  width: 38px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  position: relative;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: translate var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.switch input:checked + .switch-track {
  background: var(--jade-soft);
  border-color: var(--jade);
}
.switch input:checked + .switch-track::after {
  translate: 16px 0;
  background: var(--jade);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--jade);
  outline-offset: 2px;
}
.switch-label {
  font-size: 0.88rem;
  color: var(--text);
}

/* Range */
.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  cursor: pointer;
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--jade);
  border: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--jade);
}

/* --------------------------------------------------------------------------
   Badges, chips, indicators
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.74rem;
  font-weight: 580;
  color: var(--text-dim);
  white-space: nowrap;
}
.badge-jade {
  background: var(--jade-soft);
  border-color: color-mix(in srgb, var(--jade) 32%, transparent);
  color: var(--jade);
}
.badge-sand {
  background: var(--sand-soft);
  border-color: color-mix(in srgb, var(--sand) 32%, transparent);
  color: var(--sand);
}
.badge-sky {
  background: var(--sky-soft);
  border-color: color-mix(in srgb, var(--sky) 32%, transparent);
  color: var(--sky);
}
.badge-clay {
  background: var(--clay-soft);
  border-color: color-mix(in srgb, var(--clay) 32%, transparent);
  color: var(--clay);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: 0 0 auto;
}
.dot-live {
  background: var(--jade);
  box-shadow: 0 0 0 0 rgba(61, 220, 151, 0.6);
  animation: pulse 2.2s var(--ease-in-out) infinite;
}
.dot-warn {
  background: var(--sand);
}
.dot-off {
  background: var(--clay);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(61, 220, 151, 0.55);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(61, 220, 151, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(61, 220, 151, 0);
  }
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* A round stone used as an avatar / colour indicator. */
.stone-chip {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: 0 0 auto;
  position: relative;
}
.stone-chip[data-color='black'] {
  background: radial-gradient(circle at 33% 28%, #4a5160, #14161b 62%);
  box-shadow: inset 0 -1px 2px rgba(255, 255, 255, 0.08), 0 1px 3px rgba(0, 0, 0, 0.6);
}
.stone-chip[data-color='white'] {
  background: radial-gradient(circle at 33% 28%, #ffffff, #c6cbd4 68%);
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.4);
}
.stone-chip.sm {
  width: 16px;
  height: 16px;
}
.stone-chip.lg {
  width: 30px;
  height: 30px;
}

/* --------------------------------------------------------------------------
   Spinner & skeleton
   -------------------------------------------------------------------------- */

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to {
    rotate: 360deg;
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */

.toasts {
  position: fixed;
  z-index: 200;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(440px, calc(100vw - 32px));
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: var(--r-full);
  background: color-mix(in srgb, var(--surface-3) 92%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  max-width: 100%;
  animation: toast-in var(--dur) var(--ease);
}
.toast[data-leaving='true'] {
  animation: toast-out var(--dur-fast) var(--ease) forwards;
}
.toast-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
}
.toast[data-kind='success'] .toast-icon {
  color: var(--jade);
}
.toast[data-kind='error'] .toast-icon {
  color: var(--clay);
}
.toast[data-kind='warn'] .toast-icon {
  color: var(--sand);
}
.toast[data-kind='info'] .toast-icon {
  color: var(--sky);
}
.toast-text {
  min-width: 0;
}
.toast-action {
  margin-left: auto;
  color: var(--jade);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 2px 4px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    translate: 0 14px;
    scale: 0.96;
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    translate: 0 8px;
    scale: 0.97;
  }
}

/* --------------------------------------------------------------------------
   Modal / dialog
   -------------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal[hidden] {
  display: none;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(3, 4, 6, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in var(--dur) var(--ease);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(86dvh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 26px;
  animation: modal-in var(--dur) var(--ease);
}

.modal-title {
  font-size: 1.35rem;
  font-weight: 640;
  letter-spacing: -0.02em;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  color: var(--text-faint);
}
.modal-close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  flex-wrap: wrap;
}
.modal-actions .btn {
  flex: 1 1 140px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes modal-in {
  from {
    opacity: 0;
    translate: 0 16px;
    scale: 0.97;
  }
}
@keyframes sheet-in {
  from {
    opacity: 0;
    translate: 0 -10px;
  }
}

@media (max-width: 560px) {
  .modal {
    place-items: end center;
    padding: 0;
  }
  .modal-card {
    width: 100%;
    max-height: 88dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    animation: sheet-up var(--dur) var(--ease);
  }
  @keyframes sheet-up {
    from {
      translate: 0 100%;
    }
  }
}

/* --------------------------------------------------------------------------
   Tooltip (CSS only, for icon buttons)
   -------------------------------------------------------------------------- */

[data-tip] {
  position: relative;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  translate: -50% 4px;
  padding: 5px 9px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), translate var(--dur-fast) var(--ease);
  z-index: 80;
  box-shadow: var(--shadow-md);
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  translate: -50% 0;
}
@media (hover: none) {
  [data-tip]::after {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
}
.empty-icon {
  width: 40px;
  height: 40px;
  opacity: 0.5;
}
.empty-title {
  color: var(--text-dim);
  font-weight: 580;
}

/* --------------------------------------------------------------------------
   Utility animations
   -------------------------------------------------------------------------- */

.reveal {
  opacity: 0;
  translate: 0 18px;
  transition: opacity 0.7s var(--ease), translate 0.7s var(--ease);
}
.reveal.is-in {
  opacity: 1;
  translate: 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    translate: 0 0;
  }
}
