:root {
  --bg-top: #f6efd9;
  --bg-bottom: #d7e8f2;
  --ink: #1f2f36;
  --panel: rgba(255, 255, 255, 0.72);
  --accent: #d35d3a;
  --hex-fill: #fff8ed;
  --hex-border: #7a8d99;
  --hex-width: clamp(34px, 5.2vw, 58px);
  --hex-height: calc(var(--hex-width) * 0.86486);
  --shadow: 0 10px 22px rgba(19, 37, 46, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  touch-action: manipulation;
  background: radial-gradient(circle at 15% 15%, #fff7d8 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, #d9f2ff 0%, transparent 40%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

.app {
  width: min(980px, 94vw);
  margin: 0 auto;
  padding: 1.2rem 0.8rem 2.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(31, 47, 54, 0.18);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.5vw, 1.8rem);
  letter-spacing: 0.03em;
}

.is-hidden {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 27, 33, 0.45);
  backdrop-filter: blur(4px);
  z-index: 30;
}

.modal-card {
  width: min(92vw, 420px);
  padding: 1rem;
  border-radius: 14px;
  background: #fffdf8;
  border: 1px solid rgba(31, 47, 54, 0.18);
  box-shadow: 0 16px 30px rgba(12, 25, 31, 0.2);
}

.modal-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1.25rem;
}

.modal-card p {
  margin: 0 0 0.8rem;
  font-size: 0.95rem;
  color: #42515a;
}

#winner-title {
  color: #1f3f50;
}

#winner-text {
  font-weight: 700;
}

.modal-form {
  display: flex;
  gap: 0.55rem;
}

.modal-form input {
  flex: 1;
  border: 1px solid rgba(31, 47, 54, 0.24);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font: inherit;
}

#change-name {
  background: #567f95;
}

.sessionbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 1rem;
  padding: 0.7rem 1rem;
  border: 1px solid rgba(31, 47, 54, 0.18);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: var(--shadow);
}

.open-lobbies-panel {
  margin: 0 0 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid rgba(31, 47, 54, 0.18);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: var(--shadow);
}

.open-lobbies-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.6rem;
}

.open-lobbies-header h2 {
  margin: 0;
  font-size: 1.02rem;
}

.open-lobbies-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.lobby-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid rgba(31, 47, 54, 0.18);
  background: rgba(255, 255, 255, 0.72);
}

.lobby-item-meta {
  display: grid;
  gap: 0.18rem;
}

.lobby-id {
  font-size: 0.9rem;
  font-weight: 800;
  color: #2d3f48;
}

.lobby-detail {
  font-size: 0.83rem;
  font-weight: 700;
  color: #4c616b;
}

.lobby-empty {
  font-size: 0.9rem;
  font-weight: 700;
  color: #445961;
  padding: 0.25rem 0;
}

.lobby-item button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

#game-id-input {
  min-width: 10rem;
  border: 1px solid rgba(31, 47, 54, 0.24);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font: inherit;
}

.session-info {
  display: none;
  gap: 0.7rem;
  margin-left: auto;
  font-size: 0.92rem;
  font-weight: 700;
  color: #32434b;
}

.game-ui {
  margin: 0 0 1rem;
}

.player-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.player-card {
  width: min(44vw, 180px);
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  padding: 0.45rem 0.65rem;
  border-radius: 12px;
  border: 1px solid rgba(31, 47, 54, 0.2);
  background: rgba(255, 255, 255, 0.62);
  transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.player-self {
  align-items: center;
}

.player-card.is-active {
  border-color: rgba(33, 92, 155, 0.45);
  background: linear-gradient(165deg, rgba(219, 238, 255, 0.95), rgba(188, 219, 247, 0.95));
  box-shadow: 0 0 0 2px rgba(44, 121, 197, 0.2) inset;
}

.player-card.is-active.player-self {
  border-color: rgba(168, 68, 48, 0.45);
  background: linear-gradient(165deg, rgba(255, 227, 220, 0.95), rgba(250, 204, 191, 0.95));
  box-shadow: 0 0 0 2px rgba(196, 79, 56, 0.2) inset;
}

.avatar {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid rgba(31, 47, 54, 0.22);
  background: linear-gradient(150deg, #f6f4e9, #d7ecf4);
  font-weight: 800;
  font-size: 1.2rem;
}

.player-name {
  font-weight: 700;
  font-size: 0.93rem;
  color: #2f414a;
  text-align: center;
}

.word-build {
  position: relative;
  min-height: 58px;
  border: 1px solid rgba(31, 47, 54, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow);
}

.word-display {
  min-height: 58px;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 0 5rem;
  font-size: clamp(1.05rem, 2.4vw, 1.4rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #273a42;
}

.play-button {
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
}

.hint-button {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.status-line {
  margin-top: 0.5rem;
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.lobby-controls {
  margin-top: 0.45rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

#toggle-lobby-visibility {
  padding: 0.45rem 0.8rem;
  font-size: 0.86rem;
  background: #3f6e83;
}

.infobar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0 0 1rem;
}

.turn-banner {
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(31, 47, 54, 0.24);
  background: rgba(255, 255, 255, 0.74);
  font-size: 0.93rem;
  font-weight: 800;
  color: #2f414a;
}

.turn-banner.is-blue {
  color: #1a58aa;
}

.turn-banner.is-red {
  color: #b33f34;
}

.turn-banner.is-you {
  box-shadow: 0 0 0 2px rgba(38, 114, 42, 0.2) inset;
}

.info-pill {
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(31, 47, 54, 0.2);
  background: rgba(255, 255, 255, 0.64);
  font-size: 0.9rem;
  font-weight: 700;
  color: #33444d;
}

.info-pill.is-waiting {
  color: #8b5f16;
}

.info-pill.is-ready {
  color: #1f7a3a;
}

.info-pill.is-animated {
  animation: pop-in 420ms ease;
}

@keyframes pop-in {
  0% {
    transform: scale(0.92);
    opacity: 0.4;
  }

  55% {
    transform: scale(1.08);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.wordbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin: 0 0 1rem;
  padding: 0.7rem 1rem;
  border: 1px solid rgba(31, 47, 54, 0.18);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: var(--shadow);
}

.wordbar-label {
  font-weight: 700;
  font-size: 0.95rem;
  opacity: 0.8;
}

.wordbar-value {
  min-height: 1.6rem;
  min-width: 6ch;
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.75);
  font-size: clamp(1rem, 2.3vw, 1.35rem);
  font-weight: 750;
  letter-spacing: 0.08em;
}

.wordbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.word-status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  font-weight: 650;
  color: #41525a;
}

.word-status[data-state="success"] {
  color: #1f7a3a;
}

.word-status[data-state="error"] {
  color: #b14a35;
}

.word-status[data-state="warning"] {
  color: #8b5f16;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-weight: 650;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: filter 140ms ease;
}

button:hover {
  filter: brightness(1.06);
}

button:active {
  transform: none;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

.board-wrap {
  display: flex;
  justify-content: center;
  overflow-x: auto;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.34);
  border: 1px solid rgba(31, 47, 54, 0.16);
  box-shadow: var(--shadow);
  padding: 1.2rem;
}

.hex-board {
  --rows: 7;
  --cols: 7;
  position: relative;
  width: calc(var(--hex-width) + (var(--cols) - 1) * var(--hex-width) * 0.75);
  height: calc(var(--hex-height) * var(--rows) + var(--hex-height) * 0.5);
}

.hex {
  position: absolute;
  left: calc(var(--col) * var(--hex-width) * 0.75);
  top: calc(var(--row) * var(--hex-height) + var(--col-parity) * var(--hex-height) * 0.5);
  width: var(--hex-width);
  height: var(--hex-height);
  appearance: none;
  -webkit-appearance: none;
  padding: 0;
  border-radius: 0;
  border: 0;
  background-color: transparent;
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  color: #f3f6fa;
  clip-path: none;
  display: grid;
  place-items: center;
  font-size: clamp(1rem, 2.1vw, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  user-select: none;
  box-shadow: none;
  transform: translateY(0);
  transition: transform 140ms ease;
  touch-action: manipulation;
}

.hex--black {
  background-image: url("sprites/hexagon_black.png");
}

.hex--blue {
  background-image: url("sprites/hexagon_blue.png");
}

.hex--base-blue {
  background-image: url("sprites/hexagon_base_blue.png");
}

.hex--red {
  background-image: url("sprites/hexagon_red.png");
}

.hex--base-red {
  background-image: url("sprites/hexagon_base_red.png");
}

.hex--grey {
  background-image: url("sprites/hexagon_grey.png");
  color: var(--ink);
}

.hex:hover {
  transform: translateY(-2px);
}

.hex.is-selected {
  filter: brightness(1.15);
}

.hex:focus-visible {
  outline: none;
}

@media (max-width: 700px) {
  .app {
    width: 96vw;
  }

  .board-wrap {
    padding: 0.45rem;
    overflow-x: hidden;
  }

  .hex-board {
    --hex-width: clamp(36px, calc((96vw - 2.6rem) / 5.4), 57px);
    --hex-height: calc(var(--hex-width) * 0.88);
  }

  .wordbar-actions {
    width: 100%;
    margin-left: 0;
  }

  .session-info {
    width: 100%;
    margin-left: 0;
  }

  .player-strip {
    flex-wrap: nowrap;
    gap: 0.5rem;
  }

  .player-card,
  .player-self {
    width: calc(50% - 0.25rem);
    max-width: none;
  }

  .word-display {
    padding: 0 4rem;
  }
}
