* {
  box-sizing: border-box;
}

/* Variables for easy adjustment */
:root {
  --shield-scale: 1.2;
  --shield-rotate: 0deg;
  --shield-x: 0.5vw;
  --shield-y: -0.2vw;

  --heart-scale: 1.1;
  --heart-rotate: 0deg;
  --heart-x: -1.2vw;
  --heart-y: 1.5vw;

  --avatar-scale: 1;
  --bubble-opacity: 0.25;

  /* Combat-specific variables */
  --combat-scale: 1;
  --combat-bubble-width: calc(10 * var(--u));
  --combat-shield-scale: 1.5;
  --combat-shield-x: 2vw;
  --combat-shield-y: -0.2vw;
  --combat-heart-scale: 1;
  --combat-heart-x: 1.5vw;
  --combat-heart-y: 1vw;
  --combat-init-margin-left: calc(0 * var(--u));
  --combat-init-gap: calc(0 * var(--u));
  --combat-header-size: calc(3 * var(--u));
  --combat-timer-label-size: calc(4 * var(--u));
  --combat-timer-size: calc(7 * var(--u));
}

@import url('https://fonts.googleapis.com/css2?family=Pirata+One&display=swap');

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #000;
  font-family: 'Cinzel', serif;
  --u: calc(100vw / 100);
}

.wrapper {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Stretch to fill as requested */
  background-image: url('/public/images/background.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.fade-content {
  width: 100%;
  height: 100%;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.fade-content.fade-out {
  opacity: 0;
  pointer-events: none;
}

.fade-content.fade-in {
  opacity: 1;
  pointer-events: auto;
}

.container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #2c241a; /* Dark brown from image */
  --u: calc(100vw / 100);
}

.day {
  font-size: calc(6 * var(--u));
  font-weight: 700;
  text-transform: uppercase;
  margin-top: calc(-14.5 * var(--u));
  letter-spacing: calc(0.3 * var(--u));
}

.line {
  width: 31.5%;
  height: calc(0.25 * var(--u));
  background-color: #2c241a;
  opacity: 1;
  margin: calc(1.2 * var(--u)) 0;
}

.gametime {
  font-size: calc(20 * var(--u));
  font-weight: 700;
  line-height: 0.8;
  margin: calc(1.5 * var(--u)) 0;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.tod-icon {
  position: absolute;
  right: calc(-8 * var(--u));
  width: calc(6 * var(--u));
  height: calc(6 * var(--u));
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.5s ease;
}

.tod-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

#hour, #min {
  display: inline-block;
  min-width: calc(24 * var(--u)); /* Fixed width for digits to prevent jumping */
  text-align: center;
}

.combat-timer {
  font-size: calc(6 * var(--u));
  font-weight: 900;
  color: #d32f2f;
  margin-top: calc(-2 * var(--u));
  margin-bottom: calc(1 * var(--u));
  text-shadow: 0 0 calc(1 * var(--u)) rgba(211, 47, 47, 0.5);
}

.sep {
  display: inline-block;
}

.players {
  position: absolute;
  bottom: 24%;
  display: flex;
  gap: calc(1.5 * var(--u));
  justify-content: center;
  width: 50%;
}

/* The "Bubble" container */
.player {
  position: relative;
  display: flex;
  align-items: center;
  background: #d3b587;
  border: 0.2px solid #a78d65;
  padding: calc(0 * var(--u)) calc(0 * var(--u)) calc(0 * var(--u)) calc(0 * var(--u));
  border-radius: calc(3 * var(--u));
  height: calc(4 * var(--u));
  min-width: calc(1 * var(--u));
}

.player-avatar {
  width: calc(5 * var(--u));
  height: calc(5 * var(--u));
  display: flex;
  align-items: center;
  padding-left: 1px;
  overflow: hidden;
  z-index: 1;
  transform: scale(var(--avatar-scale));
}

.player-avatar img {
  width: 70%;
  height: 70%;
  opacity: 1;
}

.player-shield {
  position: relative;
  width: calc(4.3 * var(--u));
  height: calc(4.3 * var(--u));
  background-image: url('/public/images/shield.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: calc(1.7 * var(--u));
  color: #f0f0f0;
  z-index: 2;
  padding-bottom: calc(0.4 * var(--u));
  margin-left: calc(-1 * var(--u));
  transform: translate(var(--shield-x), var(--shield-y)) scale(var(--shield-scale)) rotate(var(--shield-rotate));
}

.player-heart {
  position: absolute;
  bottom: 0;
  left: 60%;
  width: calc(2.8 * var(--u));
  height: calc(2.8 * var(--u));
  background-image: url('/public/images/heart.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: calc(0.9 * var(--u));
  color: white;
  z-index: 3;
  padding-bottom: calc(0.2 * var(--u));
  transform: translate(var(--heart-x), var(--heart-y)) scale(var(--heart-scale)) rotate(var(--heart-rotate));
}

.player-initiative {
  position: absolute;
  top: calc(-1 * var(--u));
  left: calc(0 * var(--u));
  background: #2c2c2c;
  color: white;
  width: calc(2.2 * var(--u));
  height: calc(2.2 * var(--u));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(1 * var(--u));
  font-weight: 900;
  border: 1px solid #444;
  z-index: 4;
}

/* Combat Page Redesign */
.combat-header {
  font-size: var(--combat-header-size);
  font-weight: 700;
  text-transform: uppercase;
  margin-top: calc(-10 * var(--u));
  color: #2c241a;
}

.timer-area {
  text-align: center;
  color: #2c241a;
  margin: calc(1 * var(--u)) 0;
}

.combat-timer-label {
  font-size: var(--combat-timer-label-size);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: calc(0.2 * var(--u));
}

.combat-countdown {
  font-size: var(--combat-timer-size);
  font-weight: 900;
  line-height: 0.9;
  color: #2c241a;
  text-shadow: none;
}

.combat-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: calc(4 * var(--u)) calc(2 * var(--u));
  width: 100%;
  max-width: calc(60 * var(--u));
  margin-top: calc(2 * var(--u));
}

/* Wide Combat Bubble */
.player-wide {
  position: relative;
  display: flex;
  align-items: center;
  background: #d3b587;
  border: 0.2px solid #a78d65;
  border-radius: calc(3 * var(--u));
  height: calc(5 * var(--u));
  min-width: var(--combat-bubble-width);
  padding: 0 calc(1 * var(--u));
  transform: scale(var(--combat-scale));
}

.player-wide .player-avatar {
  width: calc(6 * var(--u));
  height: calc(6 * var(--u));
  margin-left: calc(-1 * var(--u));
  z-index: 5;
}

.player-wide .player-avatar img {
  width: 80%;
  height: 80%;
  border-radius: 50%;
}

.init-container {
  display: flex;
  align-items: center;
  gap: calc(0.5 * var(--u));
  font-weight: 900;
  font-size: calc(2.2 * var(--u));
  color: #2c241a;
  margin-left: calc(1 * var(--u));
  min-width: calc(4 * var(--u));
}

.player-wide .init-container {
  margin-left: var(--combat-init-margin-left);
  gap: var(--combat-init-gap);
}

.dice-img {
  width: calc(2.5 * var(--u));
  height: calc(2.5 * var(--u));
  object-fit: contain;
}

.player-wide .player-shield {
  transform: translate(var(--combat-shield-x), var(--combat-shield-y)) scale(var(--combat-shield-scale)) rotate(var(--shield-rotate));
}

.player-wide .player-heart {
  transform: translate(var(--combat-heart-x), var(--combat-heart-y)) scale(var(--combat-heart-scale)) rotate(var(--heart-rotate));
}


.bottom-decoration {
  position: absolute;
  bottom: 5%;
  width: 100%;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.swords-d20 {
  width: calc(20 * var(--u));
  height: calc(10 * var(--u));
  background-image: url('/public/images/swords-d20.png'); /* User should provide this or I'll use a placeholder if not exists */
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.8;
}

/* Player States */
.player.absent {
  opacity: 0.5;
  filter: grayscale(100%);
  background: #a0a0a0;
}

.player.absent .player-shield {
  filter: grayscale(100%);
  opacity: 1;
}

.player.absent .player-avatar img {
  filter: grayscale(100%);
}

.player.absent .player-heart {
  display: none;
}

.player.dead {
  opacity: 0.7;
  background: #a0a0a0;
}

.player.dead .player-shield {
  filter: grayscale(100%);
  opacity: 1;
  color: #d32f2f;
  font-family: 'Pirata One', cursive;
  font-size: calc(2 * var(--u));
}

.player.dead .player-heart {
  filter: grayscale(100%);
  opacity: 1;
  pointer-events: auto;
}

.player-wide.absent {
  opacity: 0.5;
  filter: grayscale(100%);
  background: #a0a0a0;
}

.player-wide.absent .player-shield {
  filter: grayscale(100%);
  opacity: 1;
  background-image: url('/public/images/shield.png');
}

.player-wide.absent .player-avatar img {
  filter: grayscale(100%);
}

.player-wide.absent .player-heart {
  display: none;
}

.player-wide.dead {
  opacity: 0.7;
  background: #a0a0a0;
}

.player-wide.dead .player-avatar img {
  filter: sepia(1) hue-rotate(0deg) saturate(1.5) brightness(0.7);
}

.player-wide.dead .player-shield {
  filter: grayscale(100%);
  opacity: 1;
  color: #d32f2f;
  font-family: 'Pirata One', cursive;
  font-size: calc(2.5 * var(--u));
}

.player-wide.dead .player-heart {
  filter: grayscale(100%);
  opacity: 1;
  pointer-events: auto;
}

.player-wide.dead .init-container {
  opacity: 1;
}

.player-wide.dead .dice-img {
  filter: invert(0.3) sepia(0.8);
  opacity: 0.7;
}

@keyframes timer-flash-continuous {
  0%, 100% {
    color: #ff6b6b;
    text-shadow: 0 0 calc(3 * var(--u)) rgba(211, 47, 47, 1), 0 0 calc(5 * var(--u)) rgba(211, 47, 47, 0.7);
  }
  50% {
    color: #d32f2f;
    text-shadow: 0 0 calc(1 * var(--u)) rgba(211, 47, 47, 0.3);
  }
}

@keyframes timer-flash-triple {
  0%, 100% { color: #2c241a; text-shadow: none; }
  15%, 45%, 75% { color: #ff6b6b; text-shadow: 0 0 calc(3 * var(--u)) rgba(211, 47, 47, 1); }
  25%, 55%, 85% { color: #d32f2f; text-shadow: 0 0 calc(1 * var(--u)) rgba(211, 47, 47, 0.3); }
}

@keyframes timer-flash-fade {
  0% { color: #2c241a; text-shadow: none; }
  100% { color: #d32f2f; text-shadow: 0 0 calc(1 * var(--u)) rgba(211, 47, 47, 0.5); }
}

.combat-countdown.timer-expired {
  animation: none !important;
}

.combat-countdown.timer-expired.flash-aan {
  animation: timer-flash-continuous 1.2s linear infinite !important;
}

.combat-countdown.timer-expired.flash-rood {
  animation: timer-flash-fade 0.8s ease-out forwards !important;
}

.combat-countdown.timer-expired.flash-3x {
  animation: timer-flash-triple 1.2s ease-out forwards !important;
}

.combat-countdown.timer-expired.flash-uit {
  color: #2c241a !important;
  text-shadow: none !important;
}

/* Day/Night Dimming */
.night-mode .sun-icon { opacity: 0.2; }
.night-mode .moon-icon { opacity: 1; }
.day-mode .sun-icon { opacity: 1; }
.day-mode .moon-icon { opacity: 0.2; }

/* Dice Tool Styles */
.dice-button {
  padding: 10px 15px;
  background: #444;
  border: 1px solid #555;
  color: white;
  cursor: pointer;
  border-radius: 4px;
  font-family: 'Cinzel', serif;
  font-weight: bold;
  transition: all 0.2s;
}

.dice-button:hover {
  background: #555;
  transform: scale(1.05);
}

.dice-selected-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #4a4a4a;
  border: 1px solid #555;
  border-radius: 4px;
  margin: 5px;
  cursor: grab;
}

.dice-selected-item:active {
  cursor: grabbing;
}

.dice-selected-item .remove-btn {
  background: #d32f2f;
  border: none;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 0;
}

.dice-roll-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  background: #4a4a4a;
  border: 2px solid #555;
  border-radius: 8px;
  font-weight: bold;
  font-size: 1.5em;
  color: #ffeb3b;
  position: relative;
  animation: roll-3d 0.6s ease-out;
}

@keyframes roll-3d {
  0% {
    transform: rotateX(720deg) rotateY(720deg) scale(0.5);
    opacity: 0;
  }
  50% {
    transform: rotateX(360deg) rotateY(360deg) scale(1.1);
  }
  100% {
    transform: rotateX(0) rotateY(0) scale(1);
    opacity: 1;
  }
}

.dice-roll-result .dice-type {
  font-size: 0.7em;
  opacity: 0.7;
  margin-top: 5px;
  color: #ccc;
}

.dice-roll-result.highlight {
  animation: highlight-pulse 0.5s ease-out;
}

@keyframes highlight-pulse {
  0% {
    box-shadow: 0 0 20px rgba(255, 235, 59, 0.8);
    transform: scale(1.1);
  }
  100% {
    box-shadow: 0 0 5px rgba(255, 235, 59, 0.3);
    transform: scale(1);
  }
}
