:root {
  --bg: #272730;
  --muted: #9aa0b3;
  --accent: #7d71ff;
  --tile: #22212a;
  --glass: #2f2b36;
  --success: #2c7bd9;
  /* base tile size; responsive rules will override */
  --cell-size: 120px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: #e7e9ef;
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.app {
  width: 100%;
  max-width: 1100px;
  background: transparent;
  /* no card background */
  border-radius: 12px;
  padding: 18px 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  /* keep spacing but no header bg */
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
}

.app-header .sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

main {
  display: flex;
  gap: 18px;
  margin-top: 8px;
  padding: 0 18px;
}

#boardArea {
  flex: 1;
}

.grid-wrap {
  display: flex;
  gap: 12px;
  align-items: start;
}

/* GRID: use 120px squares for headers and cells */
.grid {
  display: grid;
  grid-template-columns: var(--cell-size) repeat(3, var(--cell-size));
  grid-template-rows: var(--cell-size) repeat(3, var(--cell-size));
  gap: 12px;
  align-items: center;
}

/* top-left logo square (same size as headers/cells) */
.logo-square {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 12px;
  background: lnone;
  display: flex;
  align-items: center;
  justify-content: center;
  image-rendering: pixelated;
}

/* column headers (top row, after logo) - square same as cells */
.col-header {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 12px;
  background: var(--glass);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 8px;
  text-align: center;
  cursor: default;
}

/* row headers (first column for each row) - square same as cells */
.row-header {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 12px;
  background: var(--glass);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
  cursor: default;
}

/* inner cells */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 12px;
  background: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.02);
  position: relative;
  cursor: default;
}

.cell .word {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 1px;
}

/* Ensure long words wrap inside the tile instead of overflowing */
.cell .word {
  display: block;
  width: 100%;
  padding: 0 6px;
  text-align: center;
  line-height: 1.1;
  /* allow wrapping and break very long words */
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.cell .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}

/* Per-cell awarded points shown under the revealed word */
.cell-score {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
  margin-top: 6px;
  font-weight: 600;
  line-height: 1;
  text-align: center;
  padding: 2px 6px;
  border-radius: 6px;
  background: transparent;
}

.cell.revealed .cell-score {
  color: rgba(255, 255, 255, 0.95);
  background: rgba(0, 0, 0, 0.08);
}

.cell.hidden {
  filter: brightness(0.9);
  cursor: pointer;
}

.cell.eliminated {
  background: linear-gradient(180deg, #3a3138, #2b262b);
  color: rgba(255, 255, 255, 0.6);
  position: relative;
}

.cell.eliminated .word {
  font-weight: 800;
}

.cell.eliminated .cell-score {
  display: none;
}

.cell.eliminated .eliminated-icon {
  font-size: 26px;
  color: rgba(255, 255, 255, 0.7);
}

/* Focus styles for keyboard users on interactive (hidden) cells */
.cell.hidden:focus {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.cell.hidden:focus:not(:focus-visible) {
  outline: none;
}

.cell.revealed {
  background: linear-gradient(180deg, var(--success), #155a9b);
  color: white;
  cursor: default;
}

/* Sidebar */
aside#sidebar {
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.board-info {
  background: transparent;
  padding: 6px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.mode-toggle {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  padding: 4px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.mode-btn.active {
  background: var(--accent);
  color: white;
}

.countdown {
  font-weight: 700;
}

.info-row .icon {
  width: 28px;
  height: 28;
  border-radius: 6px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.info-row .icon i {
  font-size: 18px;
  width: 20px;
  height: 20px;
  display: inline-block;
  text-align: center;
  line-height: 1;
  color: inherit;
}

.info-row .value {
  font-family: monospace;
}

.reroll {
  margin-top: 6px;
  padding: 10px;
  border-radius: 8px;
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  font-weight: 600;
}

.dock {
  margin-top: 8px;
  padding: 8px 10px;
  width: fit-content;
  border-radius: 8px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.dock i {
  font-size: 14px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.reroll[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.reroll .rotate i {
  font-size: 14px;
}

.status {
  background: transparent;
  padding: 6px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 60;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: 420px;
  background: rgba(30, 30, 36);
  padding: 16px;
  border-radius: 10px;
  position: relative;
}

.modal-close {
  position: absolute;
  right: 10px;
  top: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

.modal-close i {
  font-size: 16px;
}

.modal-header {
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-body label {
  color: var(--muted);
  font-size: 13px;
}

.modal-body input {
  width: 100%;
  padding: 8px;
  margin-top: 8px;
  border-radius: 8px;
  border: none;
  background: #1f1e24;
  color: #fff;
}

/* Analysis view */
.analysis-title {
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 10px;
}

.analysis-panel {
  background: linear-gradient(135deg, rgba(125, 113, 255, 0.08), rgba(44, 123, 217, 0.08));
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px;
}

.analysis-card {
  background: rgba(20, 20, 26, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
}

.analysis-crumb {
  font-size: 12px;
  color: var(--muted);
  font-family: monospace;
}

.analysis-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.analysis-tags {
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  font-size: 13px;
}

.analysis-status {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.analysis-status.good {
  background: rgba(44, 123, 217, 0.16);
  color: #6cb7ff;
}

.analysis-status.almost {
  background: rgba(86, 217, 160, 0.14);
  color: #90ffd2;
}

.analysis-status.ok {
  background: rgba(255, 201, 64, 0.14);
  color: #ffd27a;
}

.analysis-status.miss {
  background: rgba(255, 175, 64, 0.16);
  color: #ffc78a;
}

.analysis-status.warn {
  background: rgba(255, 92, 92, 0.18);
  color: #ffb3b3;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.analysis-block {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
}

.analysis-block .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.analysis-block .word {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}

.analysis-block .score {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

.analysis-gap {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  color: #e7e9ef;
  font-weight: 600;
}

.analysis-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 6px;
}

.analysis-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
  font-weight: 600;
}

.analysis-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.analysis-nav-status {
  color: var(--muted);
  font-size: 13px;
  min-width: 60px;
  text-align: center;
}

.analysis-nav button,
.analysis-close {
  min-width: 88px;
}

.analysis-card.slide-in-right {
  animation: slideInRight 220ms ease;
}

.analysis-card.slide-in-left {
  animation: slideInLeft 220ms ease;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Leaderboard list */
.leaderboard-list {
  list-style: none;
  margin: 8px 0 0 0;
  padding: 0;
  max-height: 320px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  font-weight: 600;
}

.leaderboard-list li .name {
  color: #e7e9ef;
}

.leaderboard-list li .score {
  color: var(--muted);
  font-family: monospace;
}

.leaderboard-list li.top {
  background: linear-gradient(90deg, rgba(125, 113, 255, 0.18), rgba(125, 113, 255, 0.06));
}

.modal-controls {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

button {
  background: var(--accent);
  border: none;
  color: white;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

button.secondary {
  background: #6f6b7a;
}

/* Settings */
.difficulty-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.difficulty-option {
  background: transparent;
  height: 130px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.difficulty-option .opt-title {
  font-weight: 700;
}

.difficulty-option .opt-desc {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 0 6px;
}

.difficulty-option:not(.selected) {
  border: 1px solid transparent;
}

.difficulty-option.selected {
  border: 1px solid var(--accent);
}

/* Responsive / Mobile rules */
@media (max-width: 900px) {
  :root {
    /* let tiles shrink on medium screens */
    --cell-size: min(100px, calc((100vw - 64px) / 4));
  }

  body {
    padding: 16px;
  }

  main {
    flex-direction: column;
    gap: 12px;
    padding: 0 12px;
  }

  .grid-wrap {
    justify-content: center;
  }

  aside#sidebar {
    width: 100%;
    order: 2;
  }

  #boardArea {
    order: 1;
  }

  .modal-content {
    width: calc(100% - 32px);
    max-width: 420px;
  }
}

@media (max-width: 480px) {
  :root {
    --cell-size: min(80px, calc((100vw - 40px) / 4));
  }

  body {
    padding: 10px;
  }

  .grid {
    gap: 8px;
  }

  .info-row {
    font-size: 13px;
  }

  .modal-content {
    width: calc(100% - 20px);
    border-radius: 8px;
    padding: 12px;
  }

  .reroll {
    width: 100%;
  }

  /* Make buttons a little taller for touch */
  button {
    padding: 10px 12px;
  }
}

/* Very small / narrow screens: reduce size but keep 4x4 grid */
@media (max-width: 360px) {
  :root {
    /* Further reduce cell size to fit on very small screens */
    --cell-size: min(70px, calc((100vw - 32px) / 4));
  }

  body {
    padding: 8px;
  }

  .grid {
    gap: 6px;
  }

  .cell .word {
    font-size: 14px;
    padding: 0 4px;
  }

  .cell .meta {
    font-size: 9px;
  }
}
