/* Design System and Variables */
:root {
  --bg-dark: #0f0702;
  --bg-spotlight: radial-gradient(circle at 50% 40%, #2f190a 0%, #0d0501 70%);
  
  --brass-gold: #d4af37;
  --brass-highlight: #f9e79f;
  --brass-shadow: #9a7d0a;
  
  --green-light: #2e7d32;
  --green-dark: #1b5e20;
  --green-glow: rgba(76, 175, 80, 0.4);
  
  --red-light: #c62828;
  --red-dark: #880e4f;
  --red-glow: rgba(244, 67, 54, 0.4);
  
  --text-gold: #f3e5ab;
  --text-dim: #a69a80;
  --text-light: #ffffff;
  
  --card-bg: rgba(26, 13, 5, 0.6);
  --card-border: rgba(212, 175, 55, 0.25);
  
  --font-serif: 'Cinzel', Georgia, serif;
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Global Setup */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  background-image: var(--bg-spotlight);
  background-attachment: fixed;
  color: var(--text-light);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

/* Wood Grain Overlay Simulation */
body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-radial-gradient(
    circle at 50% 40%,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0.03) 4px,
    rgba(0, 0, 0, 0.05) 8px,
    rgba(0, 0, 0, 0) 12px
  );
  pointer-events: none;
  opacity: 0.8;
  z-index: 1;
}

.app-container {
  width: 100%;
  max-width: 1100px;
  min-height: 100vh;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  z-index: 2;
}

/* Connection banner */
.connection-status {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(198, 40, 40, 0.95);
  color: white;
  text-align: center;
  padding: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  backdrop-filter: blur(5px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.connection-status.hidden {
  transform: translateY(-100%);
}

.connection-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

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

/* Header */
.restaurant-header {
  text-align: center;
  margin-bottom: 40px;
}

.restaurant-title {
  font-family: var(--font-serif);
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--text-gold);
  letter-spacing: 4px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8), 0 0 20px rgba(212, 175, 55, 0.1);
  text-transform: uppercase;
}

.restaurant-subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 6px;
  margin-top: 10px;
  font-weight: 600;
}

.logo-divider-top, .logo-divider-bottom {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--brass-gold), transparent);
  margin: 15px auto;
  width: 160px;
}

.logo-divider-top {
  position: relative;
}

.logo-divider-top::after {
  content: "✦";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--brass-gold);
  background: var(--bg-dark);
  padding: 0 10px;
  font-size: 0.8rem;
}

/* Main Grid Layout */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  align-items: center;
  margin: auto 0;
}

/* Token Styling (Left Side) */
.token-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  perspective: 1200px;
}

.token-viewport {
  position: relative;
  width: 320px;
  height: 320px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

/* Dynamic drop shadow on the wood table */
.token-shadow {
  position: absolute;
  width: 290px;
  height: 290px;
  background: radial-gradient(circle, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 50%, transparent 80%);
  border-radius: 50%;
  transform: scale(1);
  transition: transform 0.4s ease, opacity 0.4s ease;
  z-index: 1;
  pointer-events: none;
  filter: blur(10px);
}

.token-wrapper {
  position: relative;
  width: 300px;
  height: 300px;
  z-index: 2;
  transform-style: preserve-3d;
}

.token {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1.1); /* springy default rotate */
}

/* Jump class will override transition during execution */
.token.jump-to-red {
  animation: jump-to-red 0.9s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.token.jump-to-green {
  animation: jump-to-green 0.9s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.token-shadow.shadow-bounce {
  animation: shadow-bounce 0.9s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Token States (Normal persistence transforms) */
.token.state-no-hangs {
  transform: rotateX(180deg);
}

.token.state-hangs {
  transform: rotateX(0deg);
}

/* Token Sides styling */
.token-side {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  backface-visibility: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 2px 5px rgba(255,255,255,0.2), inset 0 -2px 5px rgba(0,0,0,0.6);
  user-select: none;
}

/* Token Wood Background + Grain Texture */
.token-green {
  background: radial-gradient(circle, var(--green-light) 0%, var(--green-dark) 100%);
  transform: rotateX(0deg); /* Facing front */
}

.token-red {
  background: radial-gradient(circle, var(--red-light) 0%, var(--red-dark) 100%);
  transform: rotateX(180deg); /* Facing back, inverted */
}

/* Subtle wooden veneer lines layered on sides */
.token-side::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  background: repeating-linear-gradient(
    30deg,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0.05) 5px,
    rgba(255, 255, 255, 0.02) 10px
  );
  pointer-events: none;
  opacity: 0.7;
}

/* The Gold / Brass Metallic Rim */
.brass-ring {
  width: 90%;
  height: 90%;
  border-radius: 50%;
  border: 12px double var(--brass-gold);
  padding: 6px;
  background: transparent;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 
    0 0 10px rgba(0,0,0,0.5), 
    inset 0 0 10px rgba(0,0,0,0.5);
  position: relative;
}

/* Highlights on the brass ring */
.brass-ring::after {
  content: "";
  position: absolute;
  top: -6px; left: -6px; right: -6px; bottom: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: linear-gradient(135deg, var(--brass-highlight) 0%, transparent 40%, var(--brass-shadow) 70%, var(--brass-highlight) 100%) border-box;
  -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out;
  mask-composite: exclude;
  opacity: 0.7;
  pointer-events: none;
}

.inner-border {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid rgba(212, 175, 55, 0.4);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
}

/* Text styles inside the token */
.portuguese {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  letter-spacing: 3px;
  color: var(--text-gold);
  font-weight: 500;
  opacity: 0.8;
  margin-top: 10px;
}

.english {
  font-family: var(--font-serif);
  font-size: 2.1rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--text-gold);
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
  line-height: 1.1;
  text-align: center;
  max-width: 90%;
}

.decorative-stars {
  font-size: 0.65rem;
  letter-spacing: 4px;
  color: var(--brass-gold);
  margin-bottom: 5px;
}

.instruction-text {
  margin-top: 30px;
  font-size: 0.85rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  animation: pulse 2.5s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Hover Wobble animations */
@media(hover: hover) {
  .token-viewport:hover .token-shadow {
    transform: scale(0.92);
    opacity: 0.75;
  }
  
  .token-viewport:hover .token {
    transform: rotateX(var(--hover-tilt-x, -8deg)) rotateY(var(--hover-tilt-y, 8deg)) translateZ(5px);
  }
  
  .token-viewport:hover .token.state-no-hangs {
    transform: rotateX(calc(180deg + var(--hover-tilt-x, -8deg))) rotateY(var(--hover-tilt-y, 8deg)) translateZ(5px);
  }
}

/* Status Cards & History (Right Side) */
.status-panel {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.panel-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
}

.panel-header {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  letter-spacing: 3px;
  color: var(--text-gold);
  border-bottom: 1px solid rgba(212, 175, 55, 0.15);
  padding-bottom: 12px;
  margin-bottom: 24px;
  font-weight: 700;
}

/* Big dynamic status display */
.status-display {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.status-display.hidden {
  display: none !important;
}

.glow-indicator {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  position: relative;
}

.glow-indicator::after {
  content: "";
  position: absolute;
  top: -4px; left: -4px; right: -4px; bottom: -4px;
  border-radius: 50%;
  animation: glow-pulse 1.8s infinite ease-in-out;
}

.glow-indicator.green {
  background-color: #4caf50;
  box-shadow: 0 0 12px #4caf50;
}
.glow-indicator.green::after {
  border: 2px solid #4caf50;
}

.glow-indicator.red {
  background-color: #f44336;
  box-shadow: 0 0 12px #f44336;
}
.glow-indicator.red::after {
  border: 2px solid #f44336;
}

@keyframes glow-pulse {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.8); opacity: 0; }
}

.status-main {
  font-family: var(--font-serif);
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
  line-height: 1;
}

.hangs-active .status-main {
  color: #4caf50;
  text-shadow: 0 0 15px rgba(76,175,80,0.3);
}

.no-hangs-active .status-main {
  color: #f44336;
  text-shadow: 0 0 15px rgba(244,67,54,0.3);
}

.status-desc {
  font-size: 0.9rem;
  color: var(--text-light);
  font-weight: 300;
  margin-top: 5px;
  line-height: 1.4;
}

.state-timer {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.05);
}

.timer-label {
  font-size: 0.75rem;
  letter-spacing: 2px;
  color: var(--text-dim);
  font-weight: 600;
}

.timer-val {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-gold);
}

/* History logs */
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 5px;
}

/* Custom Scrollbar for history card */
.history-list::-webkit-scrollbar {
  width: 5px;
}
.history-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}
.history-list::-webkit-scrollbar-thumb {
  background: var(--brass-gold);
  border-radius: 10px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-left: 3px solid transparent;
  font-size: 0.85rem;
  animation: slide-in 0.3s ease-out;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-item.hangs {
  border-left-color: #4caf50;
}

.history-item.no_hangs {
  border-left-color: #f44336;
}

.history-status {
  font-weight: 600;
  letter-spacing: 1px;
}

.history-item.hangs .history-status {
  color: #4caf50;
}

.history-item.no_hangs .history-status {
  color: #f44336;
}

.history-time {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.history-empty {
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  padding: 20px 0;
  font-size: 0.9rem;
}

/* Footer Section */
.restaurant-footer {
  text-align: center;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid rgba(212, 175, 55, 0.1);
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 1px;
  line-height: 1.5;
}

/* Keyframe Physics Flipping Animations */

@keyframes jump-to-red {
  0% { 
    transform: rotateX(0deg) translateZ(0) scale(1);
  }
  45% { 
    transform: rotateX(100deg) translateZ(140px) scale(1.1);
  }
  /* Lands on back face */
  100% { 
    transform: rotateX(180deg) translateZ(0) scale(1);
  }
}

@keyframes jump-to-green {
  0% { 
    transform: rotateX(180deg) translateZ(0) scale(1);
  }
  45% { 
    transform: rotateX(280deg) translateZ(140px) scale(1.1);
  }
  /* Lands on front face */
  100% { 
    transform: rotateX(360deg) translateZ(0) scale(1);
  }
}

@keyframes shadow-bounce {
  0% {
    transform: scale(1);
    opacity: 0.85;
    filter: blur(10px);
  }
  45% {
    transform: scale(0.68) translateY(10px);
    opacity: 0.25;
    filter: blur(22px);
  }
  100% {
    transform: scale(1);
    opacity: 0.85;
    filter: blur(10px);
  }
}

/* Responsive Breakpoints */
@media (max-width: 820px) {
  .app-container {
    padding: 20px 10px;
  }
  
  .restaurant-title {
    font-size: 2.1rem;
    letter-spacing: 2px;
  }
  
  .main-content {
    grid-template-columns: 1fr;
    gap: 40px;
  }
  
  .token-section {
    margin-bottom: 10px;
  }
  
  .token-viewport {
    width: 280px;
    height: 280px;
  }
  
  .token-shadow {
    width: 250px;
    height: 250px;
  }
  
  .token-wrapper {
    width: 260px;
    height: 260px;
  }
  
  .portuguese {
    font-size: 0.95rem;
    margin-top: 6px;
  }
  
  .english {
    font-size: 1.8rem;
  }
}
