/* Base layout and shell styles for the replay viewer. */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.container {
  max-width: 900px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 20px;
  color: #fff;
}

header h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 18px;
  margin: 0 0 8px 0;
  text-shadow: 2px 2px 0 #000;
}

header p {
  font-size: 14px;
  color: #aaa;
  margin: 0;
}

#viewer-container {
  margin-bottom: 12px;
}

.viewer-controls {
  margin-bottom: 12px;
}

.global-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto minmax(180px, auto);
  gap: 8px;
  align-items: end;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: rgba(0, 0, 0, 0.32);
  border: 2px solid #3f4f83;
  border-radius: 8px;
}

.mobile-top-controls {
  margin-bottom: 12px;
}

.mobile-top-btn {
  background: #242d4f;
  border: 2px solid #4a4a8a;
  border-radius: 6px;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  line-height: 1.2;
  padding: 8px 9px;
  cursor: pointer;
  text-align: left;
}

.mobile-top-btn span {
  color: #ffd866;
}

.mobile-top-btn-icon {
  text-align: center;
  font-size: 13px;
  padding: 8px 0;
}

.mobile-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}

.mobile-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.mobile-sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, #0f1635 0%, #0a1028 100%);
  border-top: 2px solid #3f4f83;
  border-radius: 14px 14px 0 0;
  padding: 12px;
  transform: translateY(104%);
  transition: transform 0.2s ease;
}

.mobile-sheet.open {
  pointer-events: auto;
}

.mobile-sheet.open .mobile-sheet-backdrop {
  opacity: 1;
}

.mobile-sheet.open .mobile-sheet-panel {
  transform: translateY(0);
}

.mobile-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.mobile-sheet-head span {
  color: #9fb0e0;
  font-size: 10px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-family: 'Press Start 2P', monospace;
}

.mobile-sheet-close {
  background: #242d4f;
  border: 2px solid #4a4a8a;
  border-radius: 6px;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  line-height: 1;
  padding: 7px 8px;
  cursor: pointer;
}

.mobile-sheet-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mobile-sheet-section label {
  color: #9fb0e0;
  font-size: 9px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-family: 'Press Start 2P', monospace;
}

.mobile-sheet-section select,
.mobile-sheet-section button {
  min-height: 34px;
  border-radius: 6px;
}

.mobile-sheet-section select {
  appearance: none;
  background-color: #1d2542;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 12px 12px;
  border: 2px solid #4a4a8a;
  color: #fff;
  font-size: 12px;
  padding: 8px 34px 8px 10px;
}

.mobile-sheet-section button {
  background: #242d4f;
  border: 2px solid #4a4a8a;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 10px;
  cursor: pointer;
}

.mobile-sheet-section button:disabled,
.mobile-sheet-section select:disabled {
  opacity: 0.5;
}

.mobile-sheet-section button:hover:not(:disabled),
.mobile-sheet-close:hover {
  border-color: #ffd866;
  color: #ffd866;
}

body.mobile-sheet-open {
  overflow: hidden;
}

.global-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #9fb0e0;
  font-size: 10px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-family: 'Press Start 2P', monospace;
}

.global-controls select,
.global-controls button {
  min-height: 34px;
}

.global-controls select {
  appearance: none;
  background-color: #1d2542;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 12px 12px;
  border: 2px solid #4a4a8a;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  padding: 8px 34px 8px 10px;
  min-width: 0;
}

.global-controls select:disabled {
  opacity: 0.5;
}

.global-controls button {
  background: #242d4f;
  border: 2px solid #4a4a8a;
  border-radius: 6px;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.global-controls button:hover:not(:disabled) {
  border-color: #ffd866;
  color: #ffd866;
  background: #2d3860;
}

.global-controls button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.match-preview {
  margin-bottom: 12px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(118, 131, 171, 0.35);
  border-radius: 8px;
  color: #fff;
}

.match-preview-label {
  color: #9fb0e0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  font-family: 'Press Start 2P', monospace;
}

.match-preview-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #fff;
}

.match-preview-subtitle {
  font-size: 13px;
  line-height: 1.45;
  color: #d8e0fb;
}

.empty-state {
  border: 3px dashed #4a4a8a;
  border-radius: 12px;
  padding: 28px 20px;
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
  color: #aaa;
  margin-bottom: 12px;
}

.empty-state .icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.empty-state p {
  margin: 4px 0;
  font-size: 13px;
}

.empty-state button {
  margin-top: 10px;
  background: #242d4f;
  border: 2px solid #4a4a8a;
  border-radius: 6px;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 8px 10px;
  cursor: pointer;
}

.empty-state button:hover {
  border-color: #ffd866;
  color: #ffd866;
  background: #2d3860;
}

.error-message {
  background: #441111;
  border: 2px solid #ff4444;
  border-radius: 8px;
  padding: 16px;
  color: #ff8888;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  margin-bottom: 16px;
}

#file-input {
  display: none;
}

.instructions {
  color: #888;
  font-size: 12px;
  text-align: center;
  margin-top: 20px;
}

.instructions kbd {
  background: #333;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 6px;
  font-family: monospace;
}

.match-info {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 16px;
  color: #aaa;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.match-info .info-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.match-synopsis {
  background: rgba(14, 22, 53, 0.65);
  border: 1px solid rgba(118, 131, 171, 0.35);
  border-left: 4px solid #ffd866;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
  color: #eef1ff;
  line-height: 1.5;
}

.match-table {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(118, 131, 171, 0.3);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 0;
}

.match-table-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-width: 0;
}

.match-cell {
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  column-gap: 8px;
  align-items: baseline;
  min-width: 0;
}

.match-label {
  color: #8f99bf;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
  font-weight: 600;
}

.match-label::after {
  content: ':';
  margin-left: 2px;
}

.match-value {
  color: #fff;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.match-cell-game .match-value,
.match-cell-match-id .match-value {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}

.match-cell-seed .match-value,
.match-cell-turns .match-value {
  white-space: nowrap;
}

.match-info .info-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}

.match-info .info-label {
  color: #7683ab;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.match-info .info-value {
  color: #fff;
  min-width: 0;
}

.match-row {
  display: grid;
  gap: 10px 14px;
  min-width: 0;
}

.match-row-bottom {
  grid-template-columns: minmax(300px, 2fr) minmax(160px, 1fr);
  padding-top: 8px;
  border-top: 1px solid rgba(118, 131, 171, 0.25);
}

.match-row-bottom .info-item {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(118, 131, 171, 0.3);
  border-radius: 6px;
  padding: 8px 10px;
}

.info-players .info-value {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.winner-hidden {
  color: #666;
  font-style: italic;
}

/* Controls */
.viewer-controls {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  flex-wrap: nowrap;
}

.viewer-controls button {
  background: #333;
  border: 2px solid #555;
  border-radius: 6px;
  padding: 0 12px;
  height: 34px;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

#btn-prev,
#btn-next {
  font-size: 14px;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}

#btn-play {
  min-width: 92px;
}

.viewer-controls button:hover:not(:disabled) {
  background: #444;
  border-color: #ffd866;
}

.viewer-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.viewer-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #aaa;
  font-size: 12px;
  white-space: nowrap;
}

.viewer-controls select {
  appearance: none;
  background-color: #333;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 10px center;
  background-repeat: no-repeat;
  background-size: 12px 12px;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 0 30px 0 8px;
  height: 34px;
  color: #fff;
  font-size: 12px;
}

.viewer-controls .spacer {
  display: none;
}

.controls-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  margin-left: auto;
  flex-shrink: 0;
}

.controls-meta-status {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #aaa;
  line-height: 1;
}

.controls-meta-turn {
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  color: #9fb0e0;
  line-height: 1;
}

/* Progress Bar */
.viewer-progress {
  position: relative;
  flex: 1 1 220px;
  min-width: 180px;
  max-width: none;
  height: 8px;
  background: #222;
  border-radius: 4px;
  overflow: visible;
  cursor: pointer;
}

.speed-control {
  margin-left: 0;
}

.viewer-progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  height: 100%;
  background: linear-gradient(90deg, #4a4a8a, #ffd866);
  width: 0%;
  border-radius: 4px;
  transition: width 0.1s ease;
  z-index: 1;
}

.viewer-progress-markers {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: visible;
}

.viewer-controls button.viewer-progress-marker {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 14px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: pointer;
  display: block;
  overflow: visible;
  transition: none;
  min-width: 0;
  color: transparent;
  font-size: 0;
}

.viewer-controls button.viewer-progress-marker:hover:not(:disabled),
.viewer-controls button.viewer-progress-marker:disabled {
  background: transparent;
  border-color: transparent;
  color: transparent;
}

.viewer-controls button.viewer-progress-marker:focus-visible {
  outline: 2px solid #ffd866;
  outline-offset: 2px;
  border-radius: 4px;
}

.viewer-progress-marker-line {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 10px;
  border-radius: 999px;
  background: #ffd866;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* =========================================================================
   Mobile Responsiveness
   ========================================================================= */

/* =========================================================================
   Desktop Enhancements
   ========================================================================= */

@media (min-width: 900px) {
  .viewer-progress {
    height: 10px;
  }

  .viewer-controls button,
  .viewer-controls select {
    height: 38px;
  }

  .viewer-controls button {
    padding: 0 14px;
  }
}

@media (max-width: 900px) and (min-width: 701px) {
  .match-table-grid {
    grid-template-columns: 1fr 1fr;
  }

  .match-cell {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .match-row-bottom {
    grid-template-columns: 1fr 1fr;
  }

  .viewer-controls {
    padding: 10px 12px;
    gap: 6px;
  }

  .viewer-controls button {
    padding: 7px 10px;
    font-size: 9px;
  }

  .viewer-controls label {
    font-size: 11px;
    gap: 4px;
  }

  .viewer-controls select {
    font-size: 11px;
    padding: 3px 28px 3px 6px;
  }

  .viewer-progress {
    min-width: 110px;
    max-width: none;
  }

  .global-controls {
    grid-template-columns: 1fr 1fr;
  }

  .global-control-match,
  #btn-load-match,
  #btn-upload-match,
  .global-control-skin {
    grid-column: span 1;
  }
}

@media (max-width: 700px) {
  body {
    padding: 12px 8px 8px;
  }

  header h1 {
    font-size: 14px;
  }

  header p {
    display: none;
  }

  .global-controls {
    display: none;
  }

  .mobile-top-controls {
    display: grid !important;
    grid-template-columns: 1.3fr 0.9fr auto;
    gap: 6px;
  }

  .mobile-top-btn {
    min-height: 40px;
    font-size: 7px;
    line-height: 1.35;
    padding: 9px 8px;
  }

  .mobile-top-btn-icon {
    min-height: 40px;
    line-height: 1;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .empty-state {
    padding: 22px 12px;
  }

  .empty-state p {
    font-size: 12px;
  }

  .viewer-controls {
    padding: 10px;
    gap: 6px;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .viewer-controls button {
    padding: 6px 8px;
    font-size: 9px;
  }

  .viewer-controls label {
    font-size: 10px;
  }

  .viewer-controls select {
    font-size: 10px;
    padding: 4px 28px 4px 6px;
  }

  .match-info {
    gap: 8px;
  }

  .match-preview-title {
    font-size: 12px;
  }

  .match-preview-subtitle,
  .match-synopsis {
    font-size: 12px;
  }

  .match-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .match-table-grid {
    grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
    grid-template-areas:
      "game turns"
      "match-id seed";
    gap: 8px 10px;
  }

  .match-cell {
    grid-template-columns: max-content minmax(0, 1fr);
    column-gap: 4px;
    align-items: baseline;
  }

  .match-cell-game { grid-area: game; }
  .match-cell-match-id { grid-area: match-id; }
  .match-cell-turns { grid-area: turns; }
  .match-cell-seed { grid-area: seed; }

  .match-cell-turns,
  .match-cell-seed {
    grid-template-columns: max-content max-content;
  }

  .match-label {
    font-size: 9px;
  }

  .match-row-bottom {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding-top: 0;
    border-top: 0;
  }

  .info-players .info-value {
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .viewer-controls .spacer {
    display: none;
  }

  .viewer-progress {
    flex: 1 1 100%;
    max-width: none;
    order: 5;
    height: 6px;
  }

  .viewer-controls button.viewer-progress-marker {
    width: 16px;
    height: 12px;
  }

  .viewer-progress-marker-line {
    width: 2px;
    height: 8px;
  }

  .controls-meta {
    align-items: flex-start;
    margin-left: 0;
  }

  .instructions {
    display: none;
  }
}
