/* ============================================================================
   MOSTY (HASHIWOKAKERO) - STYLESHEET
   Themes: Zen Garden, Sea Breeze, Night Atoll, Sumi-e Ink
   ============================================================================ */

:root {
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: 'Cinzel', serif, Georgia, Cambria;
  --font-mono: 'Fira Code', monospace;

  /* Default Theme: Zen Garden */
  --bg-app: #181f1b;
  --bg-gradient: radial-gradient(circle at 50% 30%, #243029 0%, #121815 100%);
  --bg-card: rgba(28, 38, 32, 0.88);
  --bg-card-border: rgba(110, 148, 122, 0.25);
  --text-main: #edf5f0;
  --text-muted: #95ad9e;
  --accent-gold: #eab308;
  --accent-emerald: #10b981;
  --accent-crimson: #ef4444;

  /* SVG Board Colors */
  --water-bg: #141b17;
  --water-grid-dot: rgba(149, 173, 158, 0.2);
  --island-outer: #33443a;
  --island-inner: #25332b;
  --island-border: #4f695a;
  --island-text: #f0f7f2;
  --island-specular: rgba(255, 255, 255, 0.2);
  --island-glow-selected: rgba(234, 179, 8, 0.7);
  --island-glow-satisfied: rgba(16, 185, 129, 0.6);
  --island-glow-overload: rgba(239, 68, 68, 0.8);

  --bridge-line: #52371d;
  --bridge-core: #b8783d;
  --bridge-line-double: #452b14;
  --bridge-core-double: #d48b46;
  --guide-ray: rgba(234, 179, 8, 0.4);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ============================================================================
   THEMES
   ============================================================================ */

/* 2. Sea Breeze (Aquamarine Lagoon) */
body.theme-sea {
  --bg-app: #081b24;
  --bg-gradient: radial-gradient(circle at 50% 30%, #0d2f3f 0%, #05121a 100%);
  --bg-card: rgba(13, 44, 58, 0.88);
  --bg-card-border: rgba(56, 189, 248, 0.25);
  --text-main: #f0f9ff;
  --text-muted: #7dd3fc;
  --water-bg: #09202c;
  --water-grid-dot: rgba(56, 189, 248, 0.25);
  --island-outer: #0e3b4d;
  --island-inner: #082836;
  --island-border: #38bdf8;
  --island-text: #ffffff;
  --bridge-line: #223f4f;
  --bridge-core: #f59e0b;
  --bridge-core-double: #fbbf24;
  --guide-ray: rgba(56, 189, 248, 0.5);
}

/* 3. Night Atoll (Cyber Bioluminescence) */
body.theme-night {
  --bg-app: #070913;
  --bg-gradient: radial-gradient(circle at 50% 25%, #12162b 0%, #05060d 100%);
  --bg-card: rgba(18, 22, 42, 0.9);
  --bg-card-border: rgba(129, 140, 248, 0.3);
  --text-main: #e0e7ff;
  --text-muted: #a5b4fc;
  --water-bg: #090c1a;
  --water-grid-dot: rgba(129, 140, 248, 0.2);
  --island-outer: #1e2447;
  --island-inner: #131730;
  --island-border: #6366f1;
  --island-text: #ffffff;
  --bridge-line: #082f49;
  --bridge-core: #06b6d4;
  --bridge-core-double: #38bdf8;
  --island-glow-selected: rgba(244, 63, 94, 0.8);
  --island-glow-satisfied: rgba(52, 211, 153, 0.7);
  --guide-ray: rgba(6, 182, 212, 0.5);
}

/* 4. Sumi-e Ink (Traditional Japanese Rice Paper) */
body.theme-ink {
  --bg-app: #f2eee6;
  --bg-gradient: radial-gradient(circle at 50% 30%, #fbf9f4 0%, #e6e0d3 100%);
  --bg-card: rgba(255, 255, 255, 0.92);
  --bg-card-border: rgba(60, 50, 40, 0.2);
  --text-main: #2b2621;
  --text-muted: #73695e;
  --water-bg: #f8f6f0;
  --water-grid-dot: rgba(100, 90, 80, 0.2);
  --island-outer: #dfd7c8;
  --island-inner: #ffffff;
  --island-border: #2b2621;
  --island-text: #1a1614;
  --bridge-line: #1a1614;
  --bridge-core: #3a322c;
  --bridge-core-double: #1a1614;
  --island-glow-selected: rgba(194, 59, 34, 0.7);
  --island-glow-satisfied: rgba(46, 125, 50, 0.6);
  --island-glow-overload: rgba(194, 59, 34, 0.8);
  --guide-ray: rgba(194, 59, 34, 0.45);
}

/* ============================================================================
   RESET & BASE
   ============================================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font-main);
  background: var(--bg-gradient);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
}

.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-height: 100vh;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px 16px;
}

@media (max-height: 700px) {
  .app-wrapper {
    max-height: none;
    min-height: 100vh;
  }
}

.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.board-container {
  flex: 1;
  min-height: 360px;
  max-height: calc(100vh - 230px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--water-bg);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 4px 25px rgba(0, 0, 0, 0.4), var(--shadow-card);
  position: relative;
  overflow: hidden;
  padding: 10px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.2), rgba(16, 185, 129, 0.2));
  border: 1px solid var(--bg-card-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.brand-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 2px;
  line-height: 1.1;
  background: linear-gradient(135deg, #ffffff 30%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

body.theme-ink .brand-title {
  background: none;
  -webkit-text-fill-color: var(--text-main);
}

.brand-subtitle {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

.controls-center {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.select-diff {
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-main);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

body.theme-ink .select-diff {
  background: #ffffff;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Common Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  outline: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

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

.btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--bg-card-border);
}

body.theme-ink .btn-secondary {
  background: #f0eae1;
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--bg-card-border);
  color: var(--text-main);
}

.btn-icon:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

/* ============================================================================
   INFO BAR (Timer, Stage Badge, Network state)
   ============================================================================ */

.info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  font-size: 0.92rem;
  gap: 12px;
  flex-wrap: wrap;
}

.info-left, .info-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stage-badge {
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.timer-wrapper {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.3);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
}

body.theme-ink .timer-wrapper {
  background: #eae3d5;
  color: #1a1614;
}

.network-badge {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  transition: all 0.3s ease;
}

.network-badge.connected {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.network-badge.separated {
  background: rgba(234, 179, 8, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(234, 179, 8, 0.3);
}

/* ============================================================================
   BOARD PLAYFIELD (SVG CANVAS CONTAINER)
   ============================================================================ */

/* Subtle water ripples background texture */
.board-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.03) 0%, transparent 70%);
  pointer-events: none;
}

.board-svg {
  width: 100%;
  height: 100%;
  max-width: 680px;
  max-height: 680px;
  display: block;
}

/* ============================================================================
   SVG BOARD ELEMENTS & GRAPHICS
   ============================================================================ */

.grid-dot {
  fill: var(--water-grid-dot);
  transition: fill 0.3s ease;
}

/* Guide Ray Line */
.guide-ray-line {
  stroke: var(--guide-ray);
  stroke-width: 2.5;
  stroke-dasharray: 6 5;
  animation: ray-dash 1.2s linear infinite;
  pointer-events: none;
}

@keyframes ray-dash {
  to {
    stroke-dashoffset: -22;
  }
}

/* Bridge Lines */
.bridge-hitbox {
  stroke: transparent;
  cursor: pointer;
  pointer-events: stroke;
}

.bridge-hitbox:hover + .bridge-line,
.bridge-hitbox:hover ~ .bridge-line {
  filter: brightness(1.25);
}

.bridge-line {
  stroke: var(--bridge-line);
  stroke-width: 7;
  stroke-linecap: round;
  transition: stroke 0.2s ease, filter 0.2s ease;
  pointer-events: none;
}

.bridge-core {
  stroke: var(--bridge-core);
  stroke-width: 3.5;
  stroke-linecap: round;
  transition: stroke 0.2s ease;
  pointer-events: none;
}

.bridge-line.double {
  stroke: var(--bridge-line-double);
  stroke-width: 5;
}

.bridge-core.double {
  stroke: var(--bridge-core-double);
  stroke-width: 2.5;
}

/* Island Nodes */
.island-node {
  cursor: pointer;
}

.island-node:hover .island-stone-outer {
  stroke-width: 3.5;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.45));
}

.island-node:hover .island-stone-inner {
  filter: brightness(1.2);
}

.island-glow {
  fill: transparent;
  stroke: transparent;
  stroke-width: 4;
  transition: opacity 0.25s ease, stroke-width 0.25s ease;
}

.island-node.selected .island-glow {
  stroke: var(--island-glow-selected);
  filter: drop-shadow(0 0 8px var(--island-glow-selected));
  animation: pulse-glow 1.5s ease-in-out infinite;
}

.island-node.valid-target .island-glow {
  stroke: var(--guide-ray);
  stroke-dasharray: 4 4;
  animation: pulse-glow 1.2s ease-in-out infinite;
}

.island-node.satisfied .island-glow {
  stroke: var(--island-glow-satisfied);
  stroke-width: 3;
}

.island-node.overload .island-glow {
  stroke: var(--island-glow-overload);
  animation: pulse-glow 0.8s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% {
    opacity: 0.95;
    stroke-width: 4;
  }
  50% {
    opacity: 0.35;
    stroke-width: 7;
  }
}

.island-stone-outer {
  fill: var(--island-outer);
  stroke: var(--island-border);
  stroke-width: 2.5;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
  transition: fill 0.3s ease, stroke 0.3s ease;
}

.island-stone-inner {
  fill: var(--island-inner);
  transition: fill 0.3s ease;
}

.island-node.satisfied .island-stone-outer {
  stroke: var(--accent-emerald);
}

.island-node.overload .island-stone-outer {
  stroke: var(--accent-crimson);
}

.island-specular {
  fill: var(--island-specular);
  pointer-events: none;
}

.island-text {
  font-family: var(--font-main);
  font-size: 1.15rem;
  font-weight: 800;
  fill: var(--island-text);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Badges */
.satisfied-badge {
  fill: var(--accent-emerald);
  stroke: var(--water-bg);
  stroke-width: 1.5;
  animation: badge-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.overload-badge {
  fill: var(--accent-crimson);
  stroke: var(--water-bg);
  stroke-width: 1.5;
  animation: badge-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes badge-pop {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Hint Highlight Effect */
.island-node.hint-highlight .island-glow {
  stroke: #f59e0b !important;
  stroke-width: 6;
  filter: drop-shadow(0 0 12px #f59e0b) !important;
  animation: pulse-glow 0.8s ease-in-out infinite !important;
}

/* ============================================================================
   STATUS BANNER (BOTTOM ACTIONS)
   ============================================================================ */

.status-banner {
  margin-top: 12px;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  box-shadow: var(--shadow-card);
  transition: all 0.3s ease;
}

.status-banner.active {
  color: var(--accent-gold);
  border-color: rgba(234, 179, 8, 0.4);
}

.status-banner.warning {
  color: var(--accent-crimson);
  border-color: rgba(239, 68, 68, 0.4);
}

.status-banner.solved {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(5, 150, 105, 0.25));
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.6);
}

/* Floating Hint Toast */
.hint-toast {
  position: absolute;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--accent-gold);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  max-width: 520px;
  width: 90%;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: slide-up 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.hint-toast.hidden {
  display: none;
}

.hint-content {
  flex: 1;
}

.hint-title {
  font-weight: 700;
  color: var(--accent-gold);
  font-size: 0.96rem;
  margin-bottom: 4px;
}

.hint-msg {
  font-size: 0.88rem;
  color: var(--text-main);
  line-height: 1.4;
}

.btn-close-toast {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 6px;
}

@keyframes slide-up {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ============================================================================
   MODALS (Rules, Stats, Levels, Win)
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  max-width: 600px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg-card-border);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 20px 24px;
  line-height: 1.6;
  font-size: 0.95rem;
}

.modal-body h3 {
  color: var(--accent-gold);
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body ul {
  padding-left: 20px;
  margin-bottom: 14px;
}

.modal-body li {
  margin-bottom: 8px;
}

/* Victory Modal Specifics */
.win-card {
  text-align: center;
  padding: 32px 24px;
  max-width: 480px;
}

.win-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: bounce-trophy 1.2s ease infinite;
}

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

.win-title {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: #34d399;
  margin-bottom: 6px;
}

.win-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.win-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.win-stat-box {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
}

.win-stat-val {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.win-stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

/* Level Selection Grid */
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.level-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.level-card:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-2px);
  border-color: var(--accent-gold);
}

.level-card.active {
  border-color: var(--accent-emerald);
  background: rgba(16, 185, 129, 0.15);
}

.level-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.level-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.level-diff-badge {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}

.level-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Stats Modal Grid */
.stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stats-times-list {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

.time-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.9rem;
}

.time-row:last-child {
  border-bottom: none;
}

.time-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-gold);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
  }
  .controls-center, .header-right {
    justify-content: center;
  }
  .board-container {
    min-height: 400px;
  }
}

/* Link powrotu do listy gier (integracja z serwisem). */
.brand-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 8px;
  color: var(--accent-teal, #0f766e);
  background: rgba(15, 118, 110, 0.08);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.brand-back:hover {
  background: rgba(15, 118, 110, 0.16);
}
