:root {
  --bg: #0a0b10;
  --surface: #12141c;
  --surface-hover: #171a24;
  --border: rgba(255, 255, 255, 0.08);
  --red: #ff2b4d;
  --blue: #3d5bff;
  --text: #eef0ff;
  --text-dim: #7d80a3;
}

* {
  box-sizing: border-box;
}

html,
body {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  padding: 24px 40px 28px;
  position: relative;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 0%, rgba(61, 91, 255, 0.14), transparent 45%),
    radial-gradient(circle at 88% 100%, rgba(255, 43, 77, 0.14), transparent 45%),
    var(--bg);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 42px);
}

.topbar,
.board {
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-bottom: 22px;
}

.logo {
  height: 56px;
  width: auto;
  filter: drop-shadow(0 0 10px rgba(61, 91, 255, 0.45)) drop-shadow(0 0 20px rgba(255, 43, 77, 0.25));
}

.title {
  font-style: italic;
  font-weight: 800;
  font-size: 1.5rem;
  margin: 0;
  text-shadow: 0 0 14px rgba(255, 43, 77, 0.35);
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin: 4px 0 0;
  letter-spacing: 0.02em;
}

.board {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 40px;
  flex-wrap: wrap;
  width: 100%;
}

.grid-area {
  position: relative;
  flex: 0 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 150px);
  grid-template-rows: repeat(3, 150px);
  gap: 16px;
}

.tile {
  background: var(--surface);
  border: none;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.tile:hover {
  transform: translateY(-2px);
  background: var(--surface-hover);
  box-shadow: inset 0 0 0 1px rgba(255, 43, 77, 0.6), 0 0 18px rgba(255, 43, 77, 0.35);
}

.tile:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.timer-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
  flex: 0 0 270px;
  width: 270px;
  margin-left: auto;
  margin-right: 200px;
}

.ring-wrap {
  position: relative;
  width: 100%;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring-wrap svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ring-track {
  stroke: rgba(255, 255, 255, 0.08);
}

.ring-fill {
  stroke: url(#ring-gradient);
  transition: stroke-dashoffset 0.1s linear;
}

.display {
  font-family: "Consolas", "SFMono-Regular", "Courier New", monospace;
  font-weight: 700;
  font-size: 2.8rem;
  letter-spacing: 1px;
  color: #ffffff;
  text-shadow: 0 0 8px rgba(255, 43, 77, 0.6), 0 0 22px rgba(61, 91, 255, 0.35);
  position: relative;
  z-index: 1;
  font-variant-numeric: tabular-nums;
}

.badges {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  gap: 7px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.badge span#bestTime,
.badge span#attempts {
  color: var(--text);
  font-weight: 600;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 6px var(--blue);
  flex: none;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  border-radius: 10px;
  padding: 16px 22px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  width: 100%;
  color: #ffffff;
  cursor: pointer;
  background: transparent;
  transition: box-shadow 0.15s ease, background 0.15s ease, transform 0.08s ease;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-start {
  border: 1px solid var(--blue);
}

.btn-start:hover {
  background: rgba(61, 91, 255, 0.15);
  box-shadow: 0 0 18px rgba(61, 91, 255, 0.5);
}

.btn-stop {
  border: 1px solid var(--red);
}

.btn-stop:hover {
  background: rgba(255, 43, 77, 0.15);
  box-shadow: 0 0 18px rgba(255, 43, 77, 0.5);
}

.btn-reset {
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-dim);
}

.btn-reset:hover {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
}

/* Modal: anchored over the grid area only, so the timer/controls on the
   right stay fully visible and clickable while it's open. */
.modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  border-radius: 12px;
  z-index: 10;
}

.modal[hidden] {
  display: none;
}

.modal-box {
  position: relative;
  background: #e8e9ec;
  border-radius: 10px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.55);
  width: min(360px, 90%);
  height: min(360px, 80%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-image {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.modal-placeholder {
  color: #6b6f80;
  font-size: 0.9rem;
  text-align: center;
  padding: 12px;
}

.modal-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4), 0 0 14px rgba(255, 43, 77, 0.5);
}

.modal-close:hover {
  filter: brightness(1.1);
}

@media (max-width: 900px) {
  .board {
    flex-direction: column;
    justify-content: flex-start;
  }

  .grid-area {
    max-width: 100%;
    width: 100%;
    overflow-x: auto;
  }

  .timer-area {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  .controls {
    flex-direction: row;
  }

  .btn {
    width: auto;
    flex: 1 1 auto;
  }
}
