/* Global Reset & Theme Variables */
:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #121824;
  --bg-card: rgba(22, 28, 45, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  
  --neon-cyan: #00f2fe;
  --neon-blue: #4facfe;
  --neon-green: #10b981;
  --neon-red: #ef4444;
  --neon-amber: #f59e0b;
  
  --font-display: 'Outfit', 'Noto Sans JP', sans-serif;
  --shadow-neon: 0 0 10px rgba(0, 242, 254, 0.6), 0 0 20px rgba(0, 242, 254, 0.2);
  --shadow-green: 0 0 12px rgba(16, 185, 129, 0.5);
  --shadow-red: 0 0 12px rgba(239, 68, 68, 0.5);
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-display);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(79, 172, 254, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(0, 242, 254, 0.05) 0%, transparent 40%);
}

/* App Container */
.app-container {
  width: 100%;
  max-width: 1750px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Header */
.app-header {
  text-align: center;
}

.brand-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 2px;
  margin-bottom: 4px;
  background: linear-gradient(to right, #ffffff, #a1a1aa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.neon-text {
  background: linear-gradient(to right, var(--neon-cyan), var(--neon-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 8px rgba(0, 242, 254, 0.5));
}

.brand-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 4px;
}

/* Main Layout Grid */
.game-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

/* Glassmorphism Panels */
.control-panel, .board-area {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel-section h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  border-left: 3px solid var(--neon-cyan);
  padding-left: 10px;
  color: var(--text-main);
  letter-spacing: 0.5px;
}

/* Forms & Buttons */
.control-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

select {
  background: rgba(18, 24, 36, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

select:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.2);
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--neon-cyan) 0%, var(--neon-blue) 100%);
  color: #04080f;
  border: none;
  padding: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: 0 4px 15px rgba(0, 242, 254, 0.3);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 242, 254, 0.5);
  filter: brightness(1.05);
}

.primary-btn:active {
  transform: translateY(0);
}

/* Help Section rules */
.help-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.help-section strong {
  color: var(--text-main);
}

.shortcut-badge {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: monospace;
  color: var(--text-main);
}

/* Board Area (Right Column) */
.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-height: 520px;
}

/* Game HUD */
.game-hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 13, 20, 0.5);
  border-radius: 10px;
  padding: 12px 18px;
  border: 1px solid var(--border-color);
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-item {
  font-size: 0.85rem;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
}

.status-item.loading {
  color: var(--neon-amber);
}

#status-text.status-blink {
  display: inline-block;
  animation: status-pulse-blink 1.2s ease-in-out infinite;
  color: var(--neon-cyan) !important;
  font-weight: 600;
  text-shadow: 0 0 8px rgba(0, 242, 254, 0.6);
}

@keyframes status-pulse-blink {
  0%, 100% {
    opacity: 1;
    text-shadow: 0 0 6px rgba(0, 242, 254, 0.5);
  }
  50% {
    opacity: 1;
    text-shadow: 0 0 18px rgba(0, 242, 254, 1.0), 0 0 28px rgba(0, 242, 254, 0.6);
  }
}

.timer-item {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--neon-cyan);
  font-variant-numeric: tabular-nums;
  background: rgba(0, 242, 254, 0.05);
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid rgba(0, 242, 254, 0.15);
}

.icon-timer {
  animation: rotate-soft 10s linear infinite;
}

@keyframes rotate-soft {
  100% { transform: rotate(360deg); }
}

/* SVG Grid Board Styles */
.svg-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(10, 13, 20, 0.3);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  padding: 10px;
  overflow: hidden; /* Prevent scrollbars and clip zoomed SVG */
  position: relative;
  width: 100%;
  max-width: 100%;
  height: calc(100vh - 280px); /* Taller dynamic height on PC to utilize screen space */
  min-height: 500px;
  max-height: 1000px; /* Expanded limit on PC */
  touch-action: none; /* Disable default browser touch actions in container */
}

#game-svg {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
  transform-origin: 0 0; /* Important for scaling/positioning from top-left */
  touch-action: none; /* Disable default browser touch actions on SVG */
}

/* Grid Dots */
.grid-dot {
  fill: #4b5563;
}

/* Grid Cell Clue Groups */
.cell-clue-group {
}

.cell-bg {
  fill: transparent;
}

.clue-text {
  fill: #e5e7eb;
  font-size: 19px;
  font-weight: 800;
  user-select: none;
  pointer-events: none;
}

/* Satisfied/Error Clue Visual States */
.cell-clue-group.clue-satisfied .cell-bg {
  fill: rgba(16, 185, 129, 0.08);
}
.cell-clue-group.clue-satisfied .clue-text {
  fill: var(--neon-green);
}

.cell-clue-group.bg-color-a .cell-bg {
  fill: rgba(0, 150, 255, 0.22);
}
.cell-clue-group.bg-color-b .cell-bg {
  fill: rgba(239, 68, 68, 0.22);
}

.cell-clue-group.clue-error .cell-bg {
  fill: rgba(239, 68, 68, 0.08);
}
.cell-clue-group.clue-error .clue-text {
  fill: var(--neon-red);
}

/* Grid Lines (Edges) */
.grid-line {
  stroke: #1f2937;
  stroke-width: 3.5;
  stroke-linecap: round;
  pointer-events: none;
}

/* Wide clickable overlay hitbox */
.edge-hitbox {
  stroke: transparent;
  stroke-width: 16;
  stroke-linecap: round;
  cursor: pointer;
  pointer-events: stroke;
}

/* Edge UI states */
.edge-group.state-empty:hover .grid-line {
  stroke: #4b5563;
  stroke-width: 4;
}

.edge-group.state-line .grid-line {
  stroke: var(--neon-cyan);
  stroke-width: 4.5;
}

/* Cross Marks */
.cross-mark {
  opacity: 0;
  transform: scale(0.6);
  transform-origin: center;
  pointer-events: none;
}

.cross-mark line {
  stroke: #f87171;
  stroke-width: 2.2;
}

.edge-group.state-cross .cross-mark {
  opacity: 1;
  transform: scale(1);
}

.edge-group.state-cross .grid-line {
  stroke: rgba(255, 255, 255, 0.02); /* keep visible hidden background */
}

/* Action Toolbar (Bottom) */
.action-toolbar {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  background: rgba(10, 13, 20, 0.5);
  border: 1px solid var(--border-color);
  padding: 12px 18px;
  border-radius: 12px;
}

.tool-group, .history-group {
  display: flex;
  gap: 10px;
}

.divider {
  width: 1px;
  height: 32px;
  background: rgba(255, 255, 255, 0.08);
}

.tool-btn, .action-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.tool-btn:hover, .action-btn:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.tool-btn.active, .action-btn.active {
  background: rgba(0, 242, 254, 0.1) !important;
  border-color: var(--neon-cyan) !important;
  color: var(--neon-cyan) !important;
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.15) !important;
}

.action-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: var(--neon-red);
  color: #fca5a5;
}

/* Victory Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(5, 8, 15, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: #111827;
  border: 1px solid rgba(0, 242, 254, 0.3);
  border-radius: 20px;
  padding: 40px;
  width: 90%;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 242, 254, 0.15);
  transform: translateY(30px) scale(0.95);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}

.victory-trophy {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: bounce-loop 2s infinite ease-in-out;
}

@keyframes bounce-loop {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.modal-content h2 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #ffffff 0%, var(--neon-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-content p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.result-stats {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 160px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--neon-cyan);
}

/* Success Wave Animation */
@keyframes win-wave {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
    stroke-width: 7;
    filter: drop-shadow(0 0 15px rgba(0, 242, 254, 1)) brightness(1.2);
  }
  100% {
    transform: translateY(0);
  }
}

/* Responsive Rules */
@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  
  .control-panel {
    order: 2;
  }
  
  .board-area {
    order: 1;
    min-height: auto;
  }

  .svg-container {
    height: 58vh;
    min-height: 320px;
    max-height: 500px;
  }
  
  .action-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .divider {
    display: none;
  }
  
  .tool-group, .history-group {
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
  }
}

/* Golden Neon Hint Animation */
.edge-group.hint-pulse .grid-line {
  stroke: var(--neon-amber) !important;
  stroke-width: 6.5px !important;
  filter: drop-shadow(0 0 10px var(--neon-amber)) !important;
  animation: hint-glow-pulse 0.8s ease-in-out 2 alternate !important;
}

@keyframes hint-glow-pulse {
  0% {
    filter: drop-shadow(0 0 4px var(--neon-amber));
    stroke-width: 5px;
  }
  100% {
    filter: drop-shadow(0 0 15px var(--neon-amber)) drop-shadow(0 0 25px rgba(245, 158, 11, 0.4));
    stroke-width: 8px;
  }
}

/* Red Neon Error Hint Animation */
.edge-group.error-pulse .grid-line {
  stroke: var(--neon-red) !important;
  stroke-width: 6.5px !important;
  filter: drop-shadow(0 0 10px var(--neon-red)) !important;
  animation: error-glow-pulse 0.8s ease-in-out 2 alternate !important;
}

@keyframes error-glow-pulse {
  0% {
    filter: drop-shadow(0 0 4px var(--neon-red));
    stroke-width: 5px;
  }
  100% {
    filter: drop-shadow(0 0 15px var(--neon-red)) drop-shadow(0 0 25px rgba(239, 68, 68, 0.4));
    stroke-width: 8px;
  }
}

/* Mobile Screens (Under 480px) Optimization */
@media (max-width: 480px) {
  .app-container {
    padding: 12px;
    gap: 16px;
  }
  
  .control-panel, .board-area {
    padding: 16px;
    gap: 16px;
  }
  
  .brand-title {
    font-size: 2rem;
  }
  
  .brand-subtitle {
    font-size: 0.75rem;
    letter-spacing: 2px;
  }
  
  /* Hide button text on small screens to display icons compactly */
  .tool-btn span, .action-btn span {
    display: none;
  }
  
  .tool-btn, .action-btn {
    padding: 10px;
    justify-content: center;
    min-width: 42px;
    height: 42px;
  }
  
  .tool-group, .history-group {
    gap: 8px;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }
  
  .action-toolbar {
    padding: 10px;
    gap: 10px;
  }
  
  .game-hud {
    padding: 8px 12px;
  }
  
  .status-item {
    font-size: 0.8rem;
  }
  
  .timer-item {
    font-size: 0.95rem;
    padding: 2px 8px;
  }
  
  .modal-content {
    padding: 24px;
  }
  
  .modal-content h2 {
    font-size: 1.5rem;
  }
}

/* Engine indicator badge in status bar */
.engine-indicator {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  margin: 0 4px;
  border: 1px solid transparent;
}

.wasm-engine {
  background: rgba(0, 242, 254, 0.1);
  color: var(--neon-cyan);
  border-color: rgba(0, 242, 254, 0.3);
  box-shadow: 0 0 8px rgba(0, 242, 254, 0.2);
}

.js-engine {
  background: rgba(245, 158, 11, 0.1);
  color: var(--neon-amber);
  border-color: rgba(245, 158, 11, 0.3);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.2);
}

/* PC Screens Layout Optimization (Minimizing margins and gaps) */
@media (min-width: 901px) {
  .app-container {
    padding: 16px 24px;
    gap: 16px;
  }
  
  .control-panel, .board-area {
    padding: 16px 20px;
  }
  
  .control-panel {
    gap: 20px;
  }
  
  .board-area {
    gap: 16px;
  }
  
  .brand-title {
    font-size: 2.2rem;
    margin-bottom: 2px;
  }
  
  .brand-subtitle {
    font-size: 0.8rem;
    letter-spacing: 3px;
  }
}
