:root {
  --background-color: #0c1a3d;
  --theme-color: #0f3460;
  --theme-color-light: #16213e;
  --theme-color-dark: #394867;
  --accent-color: #bfd601;
  --accent-color-hover: #c13651;
  --text-color: #ffffff;
  --label-color: #ffffff;
  --text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  --sidebar-color: #1a1a2e;
  --sidebar-text-color: #ffffff;
  --border-color: rgba(255, 255, 255, 0);
}

html,
body {
  height: 100%;
}

body {
  font-family: Arial, sans-serif;
  margin: 0;
  max-width: none;
  padding: 0;
  background-color: var(--background-color);
  color: var(--text-color);
}

h1 {
  text-align: center;
  color: #ffffff;
}

.game-info {
  text-align: left;
  margin-bottom: 20px;
  font-size: 16px;
  color: var(--sidebar-text-color);
  width: 100%;
  padding: 0 8px;
}

.game-info p {
  margin: 8px 0;
  line-height: 1.4;
}

.game-info #status {
  font-weight: 600;
  margin-bottom: 12px;
}

.board {
  /* Safari-compatible square container */
  height: min(calc(100vh - 48px), calc(100vw - 200px));
  height: min(calc(100dvh - 48px), calc(100vw - 200px));
  width: min(calc(100vh - 48px), calc(100vw - 200px));
  width: min(calc(100dvh - 48px), calc(100vw - 200px));
  max-width: calc(100vw - 200px);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background-color: var(--theme-color);
  box-sizing: border-box;
  padding: 12px 24px 24px 12px;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
  position: relative;
  flex-shrink: 0;
}

.grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 2px;
  /* Safari-specific grid container fixes */
  position: relative;
  overflow: hidden;
}

.cell {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2vh;
  font-weight: bold;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
  /* Safari fallback for aspect-ratio */
  min-height: 0;
  min-width: 0;
}

/* Safari/WebKit specific fixes */
@supports not (aspect-ratio: 1/1) {
  .cell {
    height: 0;
    padding-bottom: 100%;
    position: relative;
  }
  
  .cell > * {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}

/* Safari-specific media query for better grid handling */
@media screen and (-webkit-min-device-pixel-ratio: 1) {
  .board {
    /* Force hardware acceleration on Safari */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: width, height;
  }
  
  .grid {
    /* Improve Safari grid rendering */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    backface-visibility: hidden;
  }
}

.cell .emoji {
  font-size: 2.5vh;
  line-height: 1.5;
  display: inline-block;
}

.label {
  color: var(--label-color);
  font-weight: 600;
  text-shadow: var(--text-shadow);
}

.water {
  background-color: var(--theme-color-light);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.3s ease;
}

.water:hover:not(.hit):not(.miss) {
  background-color: var(--cell-hover-color);
  transform: scale(1.05);
}

.hit {
  background-color: var(--theme-color-dark);
  border: 1px solid var(--border-color);
  animation: explosion 0.5s ease-out;
  font-size: 1.5vw;
  cursor: default;
}

.sunk {
  /* Background color wordt dynamisch ingesteld via JavaScript met teamkleur */
  border: 1px solid var(--border-color);
  font-size: 1.5vw;
  cursor: default;
}

.miss {
  background-color: var(--theme-color-dark);
  border: 1px solid var(--border-color);
  font-size: 1.5vw;
  cursor: default;
}

@keyframes explosion {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

button {
  display: block;
  margin: 20px auto;
  background-color: var(--accent-color);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s;
}

button:hover {
  background-color: var(--accent-color-hover);
}

.settings-btn {
  margin: 10px auto;
  background-color: #666;
}

.settings-btn:hover {
  background-color: #555;
}

.stats {
  text-align: center;
  margin-top: 20px;
}

.container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile Safari */
  max-width: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  padding: 20px;
  align-items: stretch;
  gap: 32px;
  box-sizing: border-box;
}

.sidebar {
  background-color: var(--sidebar-color);
  border-radius: 10px;
  padding: 24px 16px 14px 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 120px;
  color: var(--text-color);
  flex: 1 1 0;
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
  align-self: flex-start;
  overflow: hidden;
  box-sizing: border-box;
}

.sidebar-image-wrapper {
  width: 100%;
  max-height: 20vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.sidebar-image {
  max-width: 100%;
  max-height: 20vh;
  object-fit: contain;
  display: block;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  gap: 6px;
  width: 100%;
}

.sidebar-footer button {
  flex: 1;
  margin: 0;
  font-size: 13px;
  padding: 8px 8px;
  background-color: #bfd601;
  color: #000000;
}

.sidebar-footer button:hover {
  background-color: #a8c001;
}

.sidebar-footer .settings-btn {
  background-color: #666;
  color: #ffffff;
}

.sidebar-footer .settings-btn:hover {
  background-color: #555;
}

/* TEAMS SECTION STYLING */
.teams-section {
  width: 100%;
  margin-bottom: 10px;
  padding: 0 8px;
  flex: 1;
  overflow-y: auto;
}

.teams-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--sidebar-text-color);
  opacity: 0.8;
}

.header-rank {
  min-width: 35px;
  text-align: center;
}

.header-team {
  flex: 1;
  text-align: left;
  padding-left: 10px;
}

.header-points {
  min-width: 50px;
  text-align: center;
  padding-right: 10px;
}

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

.team-list-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

/* TEAM ANIMATIES */
.team-list-item {
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: transform;
}

.team-list-item.animating {
  z-index: 10;
  position: relative;
}

.team-list-item.animating .team-item {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.no-teams {
  text-align: center;
  color: var(--sidebar-text-color);
  opacity: 0.7;
  font-style: italic;
  padding: 20px 0;
}

.team-item {
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  flex: 1;
}

.team-item.active {
  background-color: white !important;
  border-color: #bfd601;
  color: black;
  border-width: 2px;
}

.team-item.active .team-name {
  color: #333;
}

.team-item.active .team-attempts {
  color: #666;
}

.team-item.active .points-value {
  color: #333;
}

.team-rank {
  color: var(--sidebar-text-color);
  font-weight: bold;
  font-size: 28px;
  padding: 8px 6px;
  min-width: 35px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.team-content {
  flex: 1;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.team-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.team-name {
  font-weight: 700;
  font-size: 18px;
  color: black;
}

.team-attempts {
  font-size: 12px;
  color: black;
  opacity: 0.8;
}

.team-points {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-width: 50px;
}

.points-value {
  font-weight: 700;
  font-size: 28px;
  color: black;
}

/* CONTEXT MENU STYLING */
.context-menu {
  position: fixed;
  background-color: var(--sidebar-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  min-width: 150px;
  overflow: hidden;
}

.context-menu-item {
  padding: 10px 15px;
  cursor: pointer;
  color: var(--sidebar-text-color);
  font-size: 14px;
  transition: background-color 0.2s ease;
  border-bottom: 1px solid var(--border-color);
}

.context-menu-item:hover {
  background-color: var(--accent-color);
  color: rgb(0, 0, 0);
}

.context-menu-item:first-child {
  border-radius: 6px 6px 0 0;
}

.context-menu-item:last-child {
  border-radius: 0 0 6px 6px;
  border-bottom: none;
}

/* Password Overlay */
.password-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-box {
  background-color: #1a1a2e;
  padding: 40px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(191, 214, 1, 0.3);
}

.password-box h2 {
  color: white;
  margin-bottom: 20px;
}

.password-box input {
  padding: 12px 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1.1rem;
  width: 200px;
  margin-bottom: 15px;
  text-align: center;
}

.password-box input:focus {
  outline: none;
  border-color: #bfd601;
  box-shadow: 0 0 10px rgba(191, 214, 1, 0.3);
}

.password-box button {
  background-color: #bfd601;
  color: black;
  border: none;
  padding: 12px 24px;
  border-radius: 5px;
  font-size: 1rem;
  cursor: pointer;
  margin: 5px;
}

.password-box button:hover {
  background-color: #a8c001;
}

.error-msg {
  color: #ff6b6b;
  font-size: 0.9rem;
  margin-top: 10px;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: #1a1a2e;
  margin: 2% auto;
  padding: 0;
  border-radius: 16px;
  width: 95%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header {
  padding: 24px 24px 16px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  margin: 0;
  color: white;
  font-size: 1.5rem;
  font-weight: 600;
}

.close {
  color: #888;
  font-size: 24px;
  font-weight: 300;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close:hover {
  color: white;
  background-color: rgba(255, 255, 255, 0.1);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.modal-footer button {
  flex: 1;
  margin: 0;
  border-radius: 5px;
}

.settings-section {
  margin-bottom: 32px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  margin-bottom: 16px;
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.ship-settings {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.ship-control {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.ship-control:hover {
  background-color: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.ship-info {
  display: flex;
  flex-direction: column;
}

.ship-name {
  font-weight: bold;
  color: white;
}

.ship-details {
  display: flex;
  gap: 15px;
  font-size: 12px;
  color: #ccc;
}

.ship-size {
  color: #ccc;
}

.ship-points {
  color: #bfd601;
  font-weight: 600;
}

.ship-count-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.count-btn {
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.2s ease;
}

.count-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.count-display {
  min-width: 40px;
  text-align: center;
  font-weight: bold;
  color: white;
  font-size: 1.1rem;
}

.language-settings {
  display: flex;
  justify-content: center;
}

.language-dropdown {
  padding: 12px 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 150px;
}

.language-dropdown:focus {
  outline: none;
  border-color: #bfd601;
  background-color: rgba(255, 255, 255, 0.15);
}

.language-dropdown option {
  background-color: #1a1a2e;
  color: white;
}

.fullscreen-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.fullscreen-btn {
  background-color: #bfd601;
  color: #000000;
  border: none;
  padding: 12px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  flex-grow: 1;
}

.fullscreen-btn:hover {
  background-color: #a8c001;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.color-settings {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.color-input {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.color-input label {
  color: white;
  font-weight: 500;
  font-size: 0.95rem;
}

.color-input input[type="color"] {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: none;
  padding: 0;
}

.image-settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.image-settings input[type="file"] {
  color: white;
  padding: 12px 16px;
  background-color: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
}

.image-settings input[type="file"]:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.reset-image-btn {
  margin: 8px 0;
  background-color: #dc3545;
  display: none;
  font-size: 0.9rem;
  padding: 8px 16px;
}

.reset-image-btn:hover {
  background-color: #dc3545;
  color: white;
}

.full-reset-btn {
  background-color: #dc3545;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s ease;
  width: 100%;
}

.full-reset-btn:hover {
  background-color: #c82333;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(220, 53, 69, 0.3);
}

/* GAME END SCREEN STYLING */
.game-end-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  padding: 15px;
  text-align: center;
  position: absolute;
  top: 0;
  left: 0;
  background-color: rgba(12, 26, 61, 0.7);
  backdrop-filter: blur(2px);
  border-radius: 8px;
  z-index: 1000;
}

.game-end-title {
  font-size: 2.5rem;
  font-weight: bold;
  color: #fff;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.game-end-subtitle {
  font-size: 1.2rem;
  color: #ccc;
  margin-bottom: 30px;
}

.top3-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 500px;
  max-height: 60%;
  overflow-y: auto;
}

.top3-team {
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.3s ease;
}

.top3-rank {
  font-size: 2rem;
  min-width: 50px;
  text-align: center;
}

.top3-team-item {
  flex: 1;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.top3-team-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top3-team-info {
  display: flex;
  align-items: center;
  gap: 15px;
  flex: 1;
}

.top3-team-name {
  font-weight: bold;
  font-size: 1.2rem;
  color: #333;
  text-align: left;
  word-wrap: break-word;
  flex: 1;
  min-width: 0;
}

.top3-team-attempts {
  display: none;
}

.top3-team-points {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
}

.top3-points-value {
  font-weight: bold;
  font-size: 1.5rem;
  color: #333;
}

.save-btn {
  background-color: #bfd601;
  color: #000000;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: normal;
  border-radius: 5px;
}

/* Custom Modal Styles */
.custom-modal {
  z-index: 3000; /* Hogere z-index dan andere modals */
}

.custom-modal-content {
  max-width: 400px;
  margin: 15% auto;
}

.custom-modal-footer {
  justify-content: center;
  gap: 12px;
}

.custom-modal-footer button {
  min-width: 80px;
}

.custom-modal-input {
  margin-top: 15px;
}

.custom-modal-input input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1rem;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.custom-modal-input input:focus {
  outline: none;
  border-color: #bfd601;
  background-color: rgba(255, 255, 255, 0.15);
}

.save-btn:hover {
  background-color: #a8c001;
}

.cancel-btn {
  background-color: #6c757d;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: normal;
  border-radius: 5px;
}

.cancel-btn:hover {
  background-color: #5a6268;
}

/* Responsive aanpassingen voor teams */
@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
  }
  .sidebar {
    margin-top: 32px;
    width: 100%;
  }

  .modal-content {
    width: 98%;
    margin: 1% auto;
    max-height: 95vh;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .ship-control {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .color-input {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .count-display {
    min-width: 32px;
  }

  .team-stats {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .teams-header {
    gap: 6px;
    font-size: 11px;
  }

  .header-rank {
    min-width: 30px;
  }

  .header-points {
    min-width: 45px;
  }

  .team-list-item {
    gap: 6px;
  }

  .team-content {
    padding: 8px;
  }

  .team-rank {
    min-width: 30px;
    font-size: 12px;
  }

  .team-name {
    font-size: 14px;
  }

  .team-attempts {
    font-size: 11px;
  }

  .points-value {
    font-size: 16px;
  }
}
