/* =====================================================================
   TIC TAC MATH - Vanilla CSS (ES6+)
   A vibrant, playful, tactile game UI
   ===================================================================== */

/* =====================================================================
   Reset & Global Styles
   ===================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: visible;
  touch-action: manipulation;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* =====================================================================
   Game Container & Layout (CSS Grid)
   ===================================================================== */

.game-container {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100vw;
  height: 100dvh;
  gap: 1rem;
  padding: 1rem;
  background: transparent;
}

/* =====================================================================
   Agent Stage (Top Row)
   ===================================================================== */

.agent-stage {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.5);
  min-height: 120px;
  flex-wrap: wrap;
}

.agent-area {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 0 0 auto;
  min-width: fit-content;
}

.agent-placeholder {
  display: none;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
  flex-shrink: 0;
}

.agent-icon {
  font-size: 3rem;
  animation: agentBob 3s ease-in-out infinite;
}

@keyframes agentBob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.agent-placeholder.agent-thinking .agent-icon {
  animation: agentThink 0.6s ease-in-out infinite;
}

@keyframes agentThink {
  0%,
  100% {
    transform: scale(1) rotate(0deg);
  }
  50% {
    transform: scale(1.1) rotate(5deg);
  }
}

.agent-placeholder.agent-celebrating .agent-icon {
  animation: agentCelebrate 0.5s ease-in-out infinite;
}

@keyframes agentCelebrate {
  0%,
  100% {
    transform: scale(1) rotate(0deg);
  }
  25% {
    transform: scale(1.15) rotate(-10deg);
  }
  75% {
    transform: scale(1.15) rotate(10deg);
  }
}

.agent-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5rem;
}

.agent-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a202c;
  letter-spacing: 0.5px;
}

.score-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: #4a5568;
  font-weight: 500;
}

.score-value {
  display: inline-block;
  min-width: 2rem;
  padding: 0.25rem 0.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 0.375rem;
  font-weight: 700;
  text-align: center;
}

.speech-bubble {
  flex: 1;
  min-width: 250px;
  background: linear-gradient(135deg, #fff5e6 0%, #ffe6f0 100%);
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: inset 0 0 0 2px #fbbf24, 0 4px 12px rgba(0, 0, 0, 0.1);
  position: relative;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #1a202c;
  font-weight: 500;
  word-wrap: break-word;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 20px;
  width: 0;
  height: 0;
  border: 6px solid transparent;
  border-top-color: #fff5e6;
  border-right-color: #fff5e6;
  filter: drop-shadow(-1px 1px 1px rgba(0, 0, 0, 0.1));
}

.speech-content {
  min-height: 1.5rem;
}

.speech-bubble.bubble-thinking .speech-content::after {
  content: '...';
  animation: bubbleThinking 1s steps(3, end) infinite;
}

@keyframes bubbleThinking {
  0%,
  20% {
    content: '';
  }
  40% {
    content: '.';
  }
  60% {
    content: '..';
  }
  80%,
  100% {
    content: '...';
  }
}

/* =====================================================================
   Game Arena (Middle Row) - The 3x3 Board
   ===================================================================== */

.game-arena {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  overflow: hidden;
  padding: 1rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.75rem;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 1.5rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 64px;
  min-height: 64px;
  padding: 1rem;
  background: linear-gradient(135deg, #fbbf24 0%, #f97316 100%);
  border: none;
  border-radius: 0.75rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 16px rgba(249, 115, 22, 0.3), 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Gradient variations for visual interest */
.cell:nth-child(1) {
  background: linear-gradient(135deg, #fbbf24 0%, #f97316 100%);
}

.cell:nth-child(2) {
  background: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
}

.cell:nth-child(3) {
  background: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
}

.cell:nth-child(4) {
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
}

.cell:nth-child(5) {
  background: linear-gradient(135deg, #10b981 0%, #14b8a6 100%);
}

.cell:nth-child(6) {
  background: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
}

.cell:nth-child(7) {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.cell:nth-child(8) {
  background: linear-gradient(135deg, #06b6d4 0%, #0ea5e9 100%);
}

.cell:nth-child(9) {
  background: linear-gradient(135deg, #14b8a6 0%, #10b981 100%);
}

/* Cell hover state */
.cell:not(.cell-taken):hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Cell active/pressed state */
.cell:not(.cell-taken):active {
  transform: translateY(-1px) scale(0.99);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Cell taken - disabled state */
.cell-taken {
  cursor: not-allowed;
  opacity: 0.9;
}

.cell.cell-player {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%) !important;
}

.cell.cell-agent {
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%) !important;
}

/* Cell content */
.cell-equation {
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.95;
  line-height: 1.2;
}

.cell-token {
  font-size: 1.75rem;
  font-weight: 700;
  animation: tokenAppear 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tokenAppear {
  0% {
    transform: scale(0) rotate(-180deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

/* Responsive: Smaller screens */
@media (max-width: 480px) {
  .board {
    max-width: 100%;
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .cell {
    font-size: 1rem;
    min-width: 56px;
    min-height: 56px;
    padding: 0.75rem;
  }

  .cell-equation {
    font-size: 0.65rem;
  }

  .cell-token {
    font-size: 1.5rem;
  }
}

/* =====================================================================
   Control Deck (Bottom Row)
   ===================================================================== */

.control-deck {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(255, 255, 255, 0.5);
  flex-wrap: wrap;
  min-height: 70px;
}

.controls-left,
.controls-right {
  display: flex;
  gap: 0.5rem;
}

.controls-center {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex: 1;
  min-width: 300px;
  justify-content: center;
  flex-wrap: wrap;
}

.config-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  align-items: flex-start;
  min-width: 120px;
}

.config-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.config-select {
  padding: 0.5rem 0.75rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  background: white;
  color: #1a202c;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231a202c' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 2rem;
}

.config-select:hover {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.config-select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* =====================================================================
   Buttons
   ===================================================================== */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 56px;
  min-height: 56px;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.05);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}

.btn-icon {
  font-size: 1.25rem;
}

.btn-label {
  display: none;
}

@media (min-width: 640px) {
  .btn-label {
    display: inline;
  }
}

.btn-reset {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.btn-reset:hover:not(:disabled) {
  background: linear-gradient(135deg, #5568d3 0%, #68408a 100%);
}

.btn-info {
  background: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
  min-width: 48px;
}

.btn-info:hover:not(:disabled) {
  background: linear-gradient(135deg, #2563eb 0%, #0891b2 100%);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =====================================================================
   Modal Overlay & Input
   ===================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  animation: modalSlideUp 0.3s ease;
}

.modal-overlay.hidden {
  display: none;
}

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

.modal-content {
  width: 100%;
  max-width: 100%;
  background: white;
  border-radius: 2rem 2rem 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalContentSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalContentSlideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }

  .modal-content {
    width: 90%;
    max-width: 500px;
    border-radius: 1.5rem;
    max-height: 90vh;
  }
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: center;
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a202c;
  margin: 0;
}

.modal-equation {
  font-family: 'Courier New', monospace;
  font-size: 1.5rem;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-body {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.input-display {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border: 2px solid #d1d5db;
  border-radius: 0.75rem;
  font-size: 2rem;
  font-weight: 700;
  color: #1a202c;
  text-align: right;
  font-family: 'Courier New', monospace;
  letter-spacing: 2px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.numeric-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.keypad-btn {
  padding: 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.75rem;
  background: white;
  color: #1a202c;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
  user-select: none;
}

.keypad-btn:hover {
  border-color: #667eea;
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.keypad-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(102, 126, 234, 0.1);
}

.keypad-delete {
  grid-column: 3;
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
  color: white;
  border-color: #ef4444;
}

.keypad-delete:hover {
  background: linear-gradient(135deg, #f87171 0%, #dc2626 100%);
  border-color: #dc2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.keypad-clear {
  grid-column: 1 / 3;
  background: linear-gradient(135deg, #fbbf24 0%, #f97316 100%);
  color: white;
  border-color: #f97316;
}

.keypad-clear:hover {
  background: linear-gradient(135deg, #fbbf24 0%, #ea580c 100%);
  border-color: #ea580c;
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.2);
}

.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.btn-modal-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  flex: 1;
}

.btn-modal-primary:hover {
  background: linear-gradient(135deg, #047857 0%, #065f46 100%);
}

.btn-modal-secondary {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  flex: 1;
}

.btn-modal-secondary:hover {
  background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
}

/* Info modal styling */
.modal-info .modal-body {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #4a5568;
}

.modal-info .modal-body p {
  margin: 0;
}

.modal-info .modal-body ul {
  margin: 1rem 0 0 1.5rem;
  padding: 0;
}

.modal-info .modal-body li {
  margin-bottom: 0.5rem;
}

.modal-info .modal-body a {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
}

.modal-info .modal-body a:hover {
  text-decoration: underline;
}

/* =====================================================================
   Responsive Design
   ===================================================================== */

@media (max-width: 640px) {
  .game-container {
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .agent-stage {
    padding: 0.75rem;
    min-height: 100px;
    gap: 1rem;
  }

  .agent-placeholder {
    width: 70px;
    height: 70px;
  }

  .agent-icon {
    font-size: 2.5rem;
  }

  .agent-name {
    font-size: 1.1rem;
  }

  .speech-bubble {
    font-size: 0.875rem;
    padding: 0.75rem;
    min-width: 100%;
  }

  .control-deck {
    padding: 0.75rem;
    gap: 0.75rem;
    min-height: auto;
  }

  .controls-center {
    min-width: 100%;
    gap: 1rem;
  }

  .config-group {
    min-width: 80px;
    flex: 1;
  }

  .btn {
    min-width: 48px;
    min-height: 48px;
    padding: 0.625rem 1rem;
    font-size: 0.75rem;
  }
}

@media (max-width: 380px) {
  .agent-area {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
    width: 100%;
  }

  .agent-info {
    width: 100%;
  }

  .speech-bubble {
    width: 100%;
  }

  .controls-center {
    gap: 0.75rem;
  }

  .config-group {
    min-width: 70px;
  }

  .config-select {
    font-size: 0.8rem;
    padding: 0.375rem 0.5rem;
    padding-right: 1.5rem;
  }
}

/* =====================================================================
   Clippy.js Agent Styling
   ===================================================================== */

/* Main Clippy container - MUST be absolute/fixed for moveTo() to work */
.clippy {
  position: fixed !important;
  z-index: 10000 !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
  pointer-events: auto !important;
}

/* Ensure all Clippy children are visible */
.clippy * {
  visibility: visible !important;
  opacity: 1 !important;
}

.clippy-window {
  z-index: 10000 !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* Clippy balloon (speech bubble) */
.clippy-balloon {
  z-index: 10001 !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* Clippy tip (pointer) */
.clippy-tip {
  z-index: 10000 !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* Clippy content */
.clippy-content {
  z-index: 10000 !important;
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* Canvas for agent sprites */
canvas {
  z-index: 10000 !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Agent container */
#clippy,
[data-clippy-type="agent"],
.agent-container {
  z-index: 10000 !important;
}
