:root {
  --accent: oklch(48% 0.08 40);
  --accent-soft: oklch(48% 0.08 40 / 12%);
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
}

body {
  padding: 32px;
}

/* Translation Buttons - Pill/Chip Style */
#translations {
  display: flex;
  gap: 8px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.translation-btn {
  padding: 8px 16px;
  border: 1px solid var(--line);
  background: var(--bg-surface);
  cursor: pointer;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  font-family: "Inter", sans-serif;
  color: var(--ink-2);
  outline: none;
  transition: all var(--transition-fast);
}

.translation-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--line-hover);
  color: var(--ink);
}

.translation-btn:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.translation-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.translation-btn.active:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Main Layout */
#main {
  display: flex;
  gap: 48px;
  align-items: flex-start;
}

/* Verse Number Grid */
#grid {
  display: grid;
  grid-template-columns: repeat(9, 40px);
  grid-template-rows: repeat(9, 40px);
  gap: 4px;
  background: var(--bg-surface);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 4px 12px rgba(0, 0, 0, 0.03);
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: all var(--transition-fast);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.cell:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: var(--accent);
  color: var(--ink);
}

.cell:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.cell.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.cell.selected:hover {
  background: var(--accent-hover);
}

/* Random Button */
#random {
  margin-top: 16px;
  padding: 12px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg-surface);
  border-radius: 50%;
  transition: all var(--transition-normal);
  font-family: "Inter", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

#random img {
  width: 40px !important;
  height: 40px !important;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}

#random:hover {
  background: var(--bg-elevated);
  border-color: var(--line-hover);
}

#random:hover img {
  opacity: 1;
}

#random:active {
  transform: scale(0.95);
}

#random:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
  outline: none;
}

/* Tooltip */
#random::after {
  content: "Random Chapter (Space or Enter)";
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-elevated);
  color: var(--ink-2);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-normal),
    visibility var(--transition-normal);
  margin-left: 12px;
  font-family: "Inter", sans-serif;
}

#random::before {
  content: "";
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: var(--line);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-normal),
    visibility var(--transition-normal);
  margin-left: 2px;
}

#random:hover::after,
#random:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Viewer - Optimized for Poetry Reading */
#viewer {
  flex: 1;
  padding: 40px 48px;
  min-height: 400px;
  background: oklch(99% 0.008 55);
  border: 1px solid var(--line);
  border-radius: 16px;
  font-size: 18px;
  line-height: 2;
  color: var(--ink);
  letter-spacing: 0.01em;
  box-shadow:
    0 1px 3px oklch(0% 0 0 / 4%),
    0 4px 12px oklch(0% 0 0 / 3%);
}

/* Fallback for viewer background */
@supports not (color: oklch(50% 0.1 0)) {
  #viewer {
    background: #fffdf9;
  }
}

#viewer em {
  color: var(--ink-3);
  font-style: italic;
}

#viewer div {
  max-width: 600px;
}

/* Responsive adjustments */
@media (max-width: 900px) {
  body {
    padding: 20px;
  }

  #main {
    flex-direction: column;
    gap: 24px;
  }

  #grid {
    justify-self: center;
  }

  #viewer {
    padding: 24px 32px;
    font-size: 17px;
  }

  #random {
    align-self: center;
  }

  #random::after,
  #random::before {
    display: none;
  }
}

@media (max-width: 420px) {
  #grid {
    grid-template-columns: repeat(9, 32px);
    grid-template-rows: repeat(9, 32px);
    padding: 8px;
    gap: 3px;
  }

  .cell {
    font-size: 11px;
  }

  #translations {
    gap: 6px;
  }

  .translation-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  #viewer {
    padding: 20px 24px;
    font-size: 16px;
    line-height: 1.9;
  }
}

/* Scroll-driven animation for verse content */
@keyframes verse-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#viewer div {
  animation: verse-fade-in 0.3s ease-out;
}
