:root {
  --bg: #0f1720;
  --panel: #18222d;
  --panel-2: #1f2c39;
  --text: #e8eef5;
  --muted: #a8b6c6;
  --border: #314253;
  --accent: #4cc9f0;
  --good: #39d353;
  --neutral: #3b82f6;
  --bad: #ff6b6b;
  --warning: #ffb700;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  --overlay: rgba(15, 23, 32, 0.78);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, system-ui, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, #183248 0%, #0f1720 45%),
    #0f1720;
  padding: 10px;
}

.shell {
  max-width: 1250px;
  margin: 0 auto;
  padding: 22px 14px 34px;
}

.scanner {
  width: 100%;
}

.topbar,
.coord-box,
.panel,
.grid-card,
#finalBox {
  background: rgba(24, 34, 45, 0.92);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 18px 20px;
  margin-bottom: 14px;
}

.title-wrap h1 {
  margin: 0 0 6px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
}

.subtitle {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
  max-width: 760px;
}

.coord-box {
  position: relative;
  text-align: center;
  padding: 16px;
  margin-bottom: 14px;
  overflow: hidden;
}

.coord-box::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(76, 201, 240, 0.012) 48%,
    rgba(76, 201, 240, 0.03) 50%,
    rgba(76, 201, 240, 0.012) 52%,
    transparent 100%
  );
  animation: coordSweep 8s linear infinite;
}

.coord-box.danger-mode {
  border-color: rgba(255, 107, 107, 0.45);
  box-shadow: var(--shadow), 0 0 18px rgba(255, 107, 107, 0.08);
}

.coord-box.danger-mode::after {
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255, 107, 107, 0.015) 48%,
    rgba(255, 107, 107, 0.04) 50%,
    rgba(255, 107, 107, 0.015) 52%,
    transparent 100%
  );
}

.coord-label,
.k {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}

#progressDisplay {
  position: relative;
  z-index: 1;
  font-family: "Courier New", monospace;
  font-size: clamp(1.45rem, 4vw, 2.35rem);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.08em;
  line-height: 1.25;
  word-break: break-word;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.panel {
  padding: 14px;
  min-width: 0;
}

.v,
.panel .v {
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.25;
  word-break: break-word;
}

.panel.solved-flash {
  animation: solvedFlash 0.9s ease;
}

.main {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 290px;
  gap: 14px;
  align-items: start;
}

.grid-card {
  position: relative;
  padding: 12px;
  overflow: hidden;
}

.grid-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 0%, rgba(76, 201, 240, 0.025) 50%, transparent 100%);
  width: 26%;
  transform: translateX(-140%);
  animation: scannerSweep 7s linear infinite;
  filter: blur(6px);
}

.grid-card.danger-mode {
  border-color: rgba(255, 107, 107, 0.45);
}

.grid-card.danger-mode::before {
  background: linear-gradient(90deg, transparent 0%, rgba(255, 107, 107, 0.04) 50%, transparent 100%);
}

.grid-frame {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#grid {
  display: grid;
  gap: 4px;
  width: min(100%, var(--grid-size, 82vh));
  height: min(var(--grid-size, 82vh), calc(100dvh - var(--reserved-height, 255px)));
  aspect-ratio: 1 / 1;
  max-width: 100%;
  max-height: calc(100dvh - var(--reserved-height, 255px));
}

.tile {
  width: 100%;
  height: 100%;
  background:
    linear-gradient(180deg,
      rgba(20, 37, 52, 0.98),
      rgba(12, 24, 34, 0.98)
    ),
    repeating-linear-gradient(
      0deg,
      rgba(255,255,255,0.02) 0px,
      rgba(255,255,255,0.02) 1px,
      transparent 1px,
      transparent 6px
    );

  border: 1px solid rgba(134, 169, 196, 0.22);
  border-radius: 9px;

  color: white;
  font-size: clamp(0.62rem, 1.2vw, 0.82rem);
  font-weight: 700;

  cursor: pointer;
  padding: 0;

  transition:
    transform 0.08s ease,
    box-shadow 0.12s ease,
    opacity 0.12s ease,
    border-color 0.12s ease;

  box-shadow:
    inset 0 0 10px rgba(255,255,255,0.02),
    inset 0 1px 0 rgba(255,255,255,0.04);

  min-width: 0;
  min-height: 0;
  position: relative;
}

.tile::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;

  width: 16%;
  height: 16%;

  border-top: 1px solid rgba(255,255,255,0.08);
  border-left: 1px solid rgba(255,255,255,0.08);

  border-top-left-radius: 4px;
  pointer-events: none;
}

.tile:hover:not(:disabled) {
  transform: translateY(-1px);

  box-shadow:
    0 0 0 1px rgba(76, 201, 240, 0.12),
    0 0 10px rgba(76, 201, 240, 0.05);

  border-color: rgba(76, 201, 240, 0.22);
}

.tile:disabled {
  cursor: default;
  opacity: 0.98;
}

.side {
  display: grid;
  gap: 12px;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.vertical-controls {
  flex-direction: column;
  align-items: stretch;
}

.vertical-controls .btn {
  width: 100%;
  min-height: 44px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border, #314253);

  background:
    linear-gradient(
      180deg,
      rgba(36, 52, 66, 0.95),
      rgba(24, 34, 45, 0.98)
    );

  color: var(--text, #e8eef5);

  border-radius: 12px;

  padding: 10px 14px;

  font-size: 0.88rem;
  font-weight: 700;

  letter-spacing: 0.02em;

  cursor: pointer;

  transition:
    transform 0.12s ease,
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    background 0.12s ease;

  box-shadow:
    0 2px 10px rgba(0,0,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.03);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);

  border-color: rgba(76, 201, 240, 0.45);

  box-shadow:
    0 0 0 1px rgba(76, 201, 240, 0.08),
    0 0 14px rgba(76, 201, 240, 0.12),
    0 4px 16px rgba(0,0,0,0.24);

  background:
    linear-gradient(
      180deg,
      rgba(42, 61, 77, 0.98),
      rgba(26, 38, 50, 1)
    );
}

.btn.secondary {
  background:
    linear-gradient(
      180deg,
      rgba(42, 52, 64, 0.95),
      rgba(28, 36, 45, 0.98)
    );
}

.btn.warning {
  border-color: rgba(255, 107, 107, 0.22);

  background:
    linear-gradient(
      180deg,
      rgba(90, 34, 34, 0.95),
      rgba(60, 20, 20, 0.98)
    );
}

.btn.warning:hover:not(:disabled) {
  transform: translateY(-1px);

  border-color: rgba(255, 107, 107, 0.42);

  background:
    linear-gradient(
      180deg,
      rgba(90, 34, 34, 0.98),
      rgba(60, 20, 20, 1)
    );

  box-shadow:
    0 0 0 1px rgba(255, 107, 107, 0.08),
    0 0 14px rgba(255, 107, 107, 0.12),
    0 4px 16px rgba(0,0,0,0.24);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
  box-shadow:
    0 2px 10px rgba(0,0,0,0.12),
    inset 0 1px 0 rgba(255,255,255,0.02);
}

#message {
  color: var(--text);
  line-height: 1.45;
  min-height: 32px;
  font-size: 0.95rem;
}

#message.warning-text {
  color: var(--bad);
  font-weight: 800;
}

#finalBox {
  display: none;
  padding: 14px;
  border-color: rgba(57, 211, 83, 0.32);
}

#finalText {
  margin-top: 6px;
  font-family: "Courier New", monospace;
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  font-weight: 800;
  line-height: 1.35;
  color: var(--good);
  word-break: break-word;
}

.signal-found {
  background: linear-gradient(180deg, #138e52, #0f6e40) !important;
  border-color: #32c47a !important;
}

.signal-very-strong {
  background: linear-gradient(180deg, #20a362, #17784a) !important;
  border-color: #45d58d !important;
}

.signal-strong {
  background: linear-gradient(180deg, #2f6fe0, #2457b1) !important;
  border-color: #6fa4ff !important;
}

.signal-medium {
  background: linear-gradient(180deg, #c98d1c, #9d6c11) !important;
  border-color: #ffd166 !important;
}

.signal-weak {
  background: linear-gradient(180deg, #bb544d, #8f3832) !important;
  border-color: #ff8f87 !important;
}

.signal-very-weak {
  background: linear-gradient(180deg, #5b2121, #421616) !important;
  border-color: #8f4b4b !important;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 9999;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  width: min(100%, 420px);
  background: rgba(24, 34, 45, 0.98);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal.fail {
  border-color: rgba(255, 107, 107, 0.4);
}

.modal.fail .modal-header {
  background: rgba(255, 107, 107, 0.1);
  border-bottom-color: rgba(255, 107, 107, 0.25);
}

.modal-header {
  padding: 14px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}

.modal-body {
  padding: 14px 16px;
  color: var(--text);
  line-height: 1.5;
  font-size: 0.96rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 0 16px 16px;
  flex-wrap: wrap;
}

.bottom-home {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 32px 0 12px;
}

.bottom-home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(76, 201, 240, 0.12);
  border: 1px solid rgba(76, 201, 240, 0.35);
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.18s ease;
}

.bottom-home-link:hover {
  background: rgba(76, 201, 240, 0.18);
  border-color: var(--accent);
  color: #7fdcff;
  transform: translateY(-1px);
}

.site-footer {
  text-align: center;
  color: var(--muted);
  margin: 12px 0 24px;
  font-size: 0.9rem;
}

@keyframes scannerSweep {
  0% { transform: translateX(-140%); }
  100% { transform: translateX(360%); }
}

@keyframes coordSweep {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

@keyframes solvedFlash {
  0% { box-shadow: var(--shadow); }
  30% {
    box-shadow:
      var(--shadow),
      0 0 0 1px rgba(57, 211, 83, 0.15),
      0 0 22px rgba(57, 211, 83, 0.12);
  }
  100% { box-shadow: var(--shadow); }
}

@keyframes warningPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.1); }
}

@media (max-width: 980px) {
  .main {
    grid-template-columns: 1fr;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #grid {
    width: min(100%, var(--grid-size, 88vw));
    height: min(var(--grid-size, 88vw), calc(100dvh - var(--reserved-height-mobile, 310px)));
    max-height: calc(100dvh - var(--reserved-height-mobile, 310px));
  }
}

@media (max-width: 620px) {
  body {
    padding: 6px;
  }

  .shell {
    padding: 12px 6px 24px;
  }

  .topbar,
  .coord-box,
  .panel,
  .grid-card {
    border-radius: 14px;
  }

  .topbar {
    padding: 16px;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 12px;
  }

  #grid {
    gap: 3px;
  }

  .tile {
    border-radius: 7px;
  }
}
