/* General Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary-color: #3a5a78; /* Deep blue for sea/sky */
  --secondary-color: #d9a566; /* Gold/bronze */
  --accent-color: #8b5d33; /* Earthy brown */
  --light-color: #f5f0e6; /* Parchment/marble */
  --dark-color: #2c3e50; /* Dark blue/black */
  --success-color: #27ae60;
  --error-color: #e74c3c;
  --info-color: #3498db;
  --shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  --border-radius: 8px;
  --font-main: "Cinzel", "Times New Roman", serif;
  --font-body: "Lato", "Segoe UI", sans-serif;
}

@import url("https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Lato:wght@300;400;700&display=swap");

html {
  height: 100%;
  width: 100%;
}

body {
  font-family: var(--font-body);
  line-height: 1.6;
  color: #333;
  background-color: var(--light-color);
  background-image: url("https://www.transparenttextures.com/patterns/parchment.png");
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  width: 100%;
}

.page-container {
  overflow-y: auto;
}

header {
  background-color: var(--primary-color);
  background-image: linear-gradient(to bottom, var(--primary-color), #2c3e50);
  color: #fff;
  padding: 0.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  position: relative;
}

header h1 {
  font-family: var(--font-main);
  font-size: 3rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
}

.subtitle {
  font-family: var(--font-body);
  font-size: 1.2rem;
  font-weight: 300;
  opacity: 0.9;
}

.back-to-game {
  display: inline-block;
  color: var(--secondary-color);
  text-decoration: none;
  font-weight: bold;
  transition: color 0.3s;
}

.back-to-game:hover {
  color: #fff;
  text-decoration: underline;
}

main {
  flex: 1;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

h2 {
  font-family: var(--font-main);
  color: var(--primary-color);
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 2rem;
  position: relative;
}

h2:after {
  content: "";
  display: block;
  width: 80px;
  height: 3px;
  background-color: var(--secondary-color);
  margin: 0.5rem auto;
}

h3 {
  font-family: var(--font-main);
  color: var(--accent-color);
}

/* Grid Layout */
.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2rem;
  margin-top: 1.5rem;
}

.grid-container .empty-state {
  grid-column: 1 / -1;
  display: block;
}

/* Region Cards */
.region-card {
  background-color: #fff;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.3s, box-shadow 0.3s;
  cursor: pointer;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.region-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.region-card:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(
    to right,
    var(--primary-color),
    var(--secondary-color)
  );
}

.region-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.region-info {
  padding: 1.5rem;
}

.region-info h3 {
  margin-bottom: 0.5rem;
  color: var(--primary-color);
  font-size: 1.5rem;
}

/* Encounter Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: none;
  overflow: hidden;
}

.modal.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background-color: #fff;
  border-radius: 8px;
  width: 90%;
  height: 90vh;
  padding: 20px;
  position: relative;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  border: 2px solid var(--secondary-color);

  /* Simple row layout */
  display: flex;
  flex-direction: column;
}

.modal-content h2 {
  color: var(--primary-color);
  text-align: center;
  margin-bottom: 20px;
}

/* Move close button to be the first item in flex */
.close-button {
  font-size: 24px;
  cursor: pointer;
  color: #999;
  align-self: flex-end;
  margin-bottom: 10px;
}

.encounter-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
}

.encounter-layout {
  /* Take remaining height */
  flex: 1;
  /* Column layout */
  display: flex;
  /* Critical for flex children to size properly */
  height: 0;
  overflow: hidden;
}

.encounter-region-image-container {
  width: 40%;
  padding-right: 20px;
}

.encounter-region-image {
  height: 100%;
  width: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.encounter-text-content {
  width: 60%;
  /* Only text content scrolls */
  overflow-y: auto;
  padding: 15px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.8);
}

/* Hide the encounter-description since it's no longer used */
#encounter-description {
  /* display: none; */
}

@media (max-width: 768px) {
  .modal-content {
    min-width: unset;
    width: 95%;
  }

  .encounter-layout {
    flex-direction: column;
    height: auto;
    /* On mobile, let the container scroll rather than just the text */
    overflow-y: auto;
  }

  .encounter-region-image-container {
    width: 100%;
    padding-right: 0;
    margin-bottom: 20px;
  }

  .encounter-region-image {
    max-height: 30vh;
  }

  .encounter-text-content {
    width: 100%;
    /* No fixed height on mobile */
    max-height: none;
    /* No need for text area to scroll, whole container scrolls */
    overflow-y: visible;
  }
}

/* Admin Panel */
.admin-page {
  background-color: #f8f9fa;
}

.tabs {
  display: flex;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #ddd;
  justify-content: center;
}

.tab-button {
  padding: 0.75rem 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  color: #777;
  transition: color 0.3s;
  font-family: var(--font-main);
}

.tab-button:hover {
  color: var(--primary-color);
}

.tab-button.active {
  color: var(--primary-color);
  border-bottom: 3px solid var(--secondary-color);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-content > h2 {
  margin-bottom: 2rem;
}

.tab-content > div {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  justify-content: center;
}

.card-title {
  padding: 0.5rem;
  border-bottom: 1px solid #ddd;
}

form {
  overflow-y: auto;
  padding: 1rem;
}

.form-container,
.list-container {
  background-color: #fff;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
  flex: 1;
  min-width: 300px;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  max-height: 670px;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--accent-color);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  font-family: var(--font-body);
  transition: border-color 0.3s;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
  max-width: 300px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(58, 90, 120, 0.2);
}

.form-group small {
  display: block;
  margin-top: 0.25rem;
  color: #777;
  font-size: 0.85rem;
}

.btn {
  background-color: var(--primary-color);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s;
  font-family: var(--font-body);
  font-weight: bold;
  display: block;
  margin: 0 auto;
}

.btn:hover {
  background-color: #2c4a68;
}

.btn-danger {
  background-color: var(--error-color);
}

.btn-danger:hover {
  background-color: #c0392b;
}

.hidden {
  display: none;
}

.loading {
  text-align: center;
  color: #777;
  padding: 2rem;
  font-style: italic;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: #777;
  font-style: italic;
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: var(--border-radius);
  margin: 2rem auto;
  max-width: 500px;
  width: 90%;
}

/* Item List */
.item-list {
  list-style: none;
}

/* Region Header */
.region-header {
  background-color: var(--primary-color);
  color: white;
  padding: 0.5rem 1rem;
  margin-top: 0.5rem;
  border-radius: 4px 4px 0 0;
}

.region-header h3 {
  margin: 0;
  color: white;
  font-size: 1.1rem;
  font-weight: 500;
}

.region-header + .item {
  border-top: none;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

/* List Controls */
.list-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background-color: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 1rem;
  border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.filter-container,
.sort-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.filter-container label,
.sort-container label {
  font-weight: 500;
  color: var(--accent-color);
  white-space: nowrap;
}

.filter-container select,
.sort-container select {
  padding: 0.5rem;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background-color: white;
  font-family: var(--font-body);
  min-width: 150px;
}

.item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid #eee;
  transition: background-color 0.3s;
  background-color: #fff;
}

.item:hover {
  background-color: #f9f9f9;
}

.item:last-child {
  border-bottom: none;
}

.item-info {
  flex: 1;
}

.item-info h4 {
  margin-bottom: 0.25rem;
  color: var(--primary-color);
}

.item-info p {
  color: #777;
  font-size: 0.9rem;
}

.item-actions {
  display: flex;
  gap: 0.5rem;
}

.item-actions button {
  padding: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: #777;
  transition: color 0.3s;
  font-size: 1.2rem;
}

.item-actions button:hover {
  color: var(--primary-color);
}

.item-actions .delete-btn:hover {
  color: var(--error-color);
}

/* Image Input Container */
.image-input-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.url-input-container {
  flex: 1;
  min-width: 250px;
}

.upload-input-container {
  display: flex;
  align-items: center;
}

.upload-label {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background-color: var(--secondary-color);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
  font-weight: bold;
}

.upload-label:hover {
  background-color: #c69555;
}

input[type="file"] {
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  z-index: -1;
}

/* Image Preview */
#image-preview-container {
  margin-top: 1rem;
  text-align: center;
}

.preview-wrapper {
  display: inline-block;
  position: relative;
  margin: 0 auto;
  padding: 5px;
  background-color: #fff;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

.image-preview,
#image-preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: 4px;
  border: 1px solid #ddd;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#clear-image {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: var(--error-color);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.3s;
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#clear-image:hover {
  background-color: #c0392b;
}

.btn-small {
  background-color: var(--primary-color);
  color: #fff;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background-color 0.3s;
}

.btn-small:hover {
  background-color: #2c4a68;
}

.url-input-disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
  margin-right: 0.5rem;
}

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

/* Disabled Button */
button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Message Notifications */
.message {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  background-color: var(--info-color);
  color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  z-index: 2000;
  opacity: 0;
  transform: translateY(-20px);
  transition: opacity 0.3s, transform 0.3s;
}

.message.show {
  opacity: 1;
  transform: translateY(0);
}

.message.success {
  background-color: var(--success-color);
}

.message.error {
  background-color: var(--error-color);
}

.message.info {
  background-color: var(--info-color);
}

/* Probability Preview */
.probability-preview {
  margin-top: 5px;
  color: #666;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .grid-container {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
  }

  .tabs {
    flex-direction: column;
  }

  .tab-button {
    width: 100%;
    text-align: left;
  }

  header h1 {
    font-size: 2rem;
  }

  .subtitle {
    font-size: 1rem;
  }
}

#encounters-list,
#regions-list {
  overflow-y: auto;
}

.btn-secondary {
  background-color: var(--secondary-color);
  color: #fff;
}

.btn-secondary:hover {
  background-color: #c69555;
}
