:root {
  --ink: #00005a;
  --muted: #66717a;
  --line: #e1dde4;
  --paper: #fffaf0;
  --panel: #fffafa;
  --panel-soft: rgba(255, 250, 250, 0.8);
  --board: #adb0bb;
  --board-dark: #086788;
  --tile: #ead594;
  --tile-edge: #dab94f;
  --sea: #086788;
  --coral: #dab94f;
  --plum: #00005a;
  --gold: #ead594;
  --green: #086788;
  --red: #dab94f;
  --blue: #086788;
  --shadow: 0 18px 42px rgba(0, 0, 90, 0.12);
  --shadow-soft: 0 10px 28px rgba(0, 0, 90, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(234, 213, 148, 0.36), transparent 22rem),
    linear-gradient(135deg, rgba(8, 103, 136, 0.16), transparent 34rem),
    linear-gradient(180deg, #fffafa, var(--paper)),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background-color 150ms ease,
    border-color 150ms ease,
    opacity 150ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
  max-width: 1480px;
  margin: 0 auto 18px;
  padding: 12px;
  border: 1px solid rgba(225, 221, 228, 0.92);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.brand-block,
.status-strip,
.top-actions,
.score-card,
.tile-bag,
.connection-card,
.check-row {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid rgba(0, 0, 90, 0.88);
  border-radius: 12px;
  background: linear-gradient(145deg, #fffaf0, var(--tile));
  box-shadow:
    0 4px 0 var(--tile-edge),
    0 12px 24px rgba(218, 185, 79, 0.2);
  font-size: 24px;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 27px;
  line-height: 1;
  letter-spacing: 0;
}

.brand-block p,
.status-strip,
.tile-bag span,
.score-card span,
.move-log span,
.connection-card p,
.chat-panel p,
label span {
  color: var(--muted);
  font-size: 13px;
}

.status-strip {
  justify-self: center;
  min-width: 220px;
  justify-content: center;
  gap: 9px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(8, 103, 136, 0.16);
}

.top-actions {
  justify-content: flex-end;
  gap: 10px;
}

.icon-button,
.primary-button,
.secondary-button,
.submit-button,
.toolbar-actions button {
  min-height: 42px;
  border-radius: 10px;
  font-weight: 800;
}

.icon-button {
  width: 42px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.primary-button,
.submit-button {
  color: white;
  background: linear-gradient(135deg, var(--sea), var(--ink));
  box-shadow: 0 12px 24px rgba(0, 0, 90, 0.18);
}

.primary-button {
  padding: 0 18px;
  white-space: nowrap;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(210px, 260px) minmax(420px, 1fr) minmax(250px, 320px);
  gap: 16px;
  align-items: start;
  max-width: 1480px;
  margin: 0 auto;
}

.player-panel,
.details-panel,
.board-area {
  display: grid;
  gap: 12px;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.score-card,
.tile-bag,
.move-log,
.connection-card,
.word-check,
.chat-panel,
.board-toolbar,
.rack-zone {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
}

.score-card {
  position: relative;
  gap: 12px;
  min-height: 78px;
  padding: 15px;
  overflow: hidden;
}

.score-card.current {
  border-color: rgba(8, 103, 136, 0.38);
  background:
    linear-gradient(90deg, rgba(8, 103, 136, 0.08), transparent 62%),
    var(--panel);
  box-shadow:
    0 0 0 3px rgba(8, 103, 136, 0.1),
    var(--shadow-soft);
}

.score-card strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.score-card small {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.avatar {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.sea {
  background: var(--sea);
}

.coral {
  background: var(--coral);
}

.tile-bag {
  justify-content: space-between;
  gap: 16px;
  padding: 15px;
}

.tile-bag strong {
  display: block;
  font-size: 24px;
}

.bag-meter {
  width: 88px;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #f3f0f8;
}

.bag-meter span {
  display: block;
  width: 58%;
  height: 100%;
  background: var(--gold);
}

.move-log,
.word-check,
.chat-panel {
  padding: 17px;
}

h2 {
  margin-bottom: 12px;
  font-size: 15px;
  letter-spacing: 0;
}

.move-log ol {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.move-log li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
}

.move-log strong {
  letter-spacing: 0;
}

.move-log em {
  color: var(--green);
  font-style: normal;
  font-weight: 800;
}

.board-area {
  min-width: 0;
}

.board-toolbar,
.rack-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.board-toolbar span {
  color: var(--muted);
  font-size: 12px;
}

.board-toolbar strong {
  display: block;
  font-size: 26px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.toolbar-actions button,
.secondary-button {
  padding: 0 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(0, 0, 90, 0.06);
}

.board-wrap {
  width: 100%;
  padding: min(2vw, 18px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent 34%),
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.18), transparent 18rem),
    var(--board-dark);
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  width: min(100%, calc(100vh - 242px));
  min-width: 360px;
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 2px solid rgba(0, 0, 90, 0.36);
  border-radius: 10px;
  background: var(--board);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  padding: 2px;
  border: 1px solid rgba(0, 0, 90, 0.14);
  color: rgba(0, 0, 90, 0.58);
  font-size: clamp(6px, 0.58vw, 9px);
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.cell.dw {
  background: #fdf3f4;
}

.cell.tw {
  background: #ead594;
  color: rgba(0, 0, 90, 0.86);
}

.cell.dl {
  background: #e1dde4;
}

.cell.tl {
  background: #086788;
  color: rgba(255, 255, 255, 0.84);
}

.cell.center::after {
  content: "*";
  font-size: 20px;
}

.tile {
  position: relative;
  display: grid;
  width: 86%;
  height: 86%;
  place-items: center;
  border: 1px solid rgba(118, 99, 35, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.38), transparent 44%),
    linear-gradient(145deg, #fff5c8, var(--tile));
  box-shadow:
    0 3px 0 var(--tile-edge),
    0 10px 18px rgba(0, 0, 90, 0.1);
  color: var(--ink);
  font-weight: 900;
  user-select: none;
}

.tile small {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 10px;
}

.rack-zone {
  align-items: stretch;
}

.rack {
  display: grid;
  grid-template-columns: repeat(7, 48px);
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.rack .tile {
  width: 48px;
  height: 48px;
}

.tile.selected {
  outline: 3px solid rgba(8, 103, 136, 0.42);
  transform: translateY(-5px);
}

.preview-tile {
  outline: 3px solid rgba(218, 185, 79, 0.58);
}

.empty-rack,
.empty-log {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.valid-text {
  color: var(--green) !important;
}

.turn-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.submit-button {
  padding: 0 18px;
  background: linear-gradient(135deg, #086788, var(--ink));
}

.connection-card {
  gap: 12px;
  padding: 16px;
  flex-wrap: wrap;
}

.connection-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background:
    linear-gradient(90deg, transparent 38%, rgba(255, 255, 255, 0.9) 38% 48%, transparent 48%),
    linear-gradient(135deg, var(--sea), var(--plum));
}

.check-row {
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.check-row strong {
  color: var(--muted);
}

.check-row.valid strong {
  color: var(--green);
}

.chat-panel {
  display: grid;
  gap: 10px;
}

.chat-panel p {
  padding: 10px;
  border-radius: 10px;
  background: rgba(243, 240, 248, 0.88);
}

label {
  display: grid;
  gap: 6px;
}

.name-field {
  flex-basis: 100%;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: white;
}

@media (max-width: 1080px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .status-strip {
    order: 3;
    grid-column: 1 / -1;
    width: 100%;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .board-area {
    order: 1;
  }

  .player-panel {
    order: 2;
  }

  .details-panel {
    order: 3;
  }

  .details-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .move-log,
  .chat-panel {
    grid-column: 1 / -1;
  }

  .board {
    width: min(100%, 720px);
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 8px;
  }

  .topbar {
    gap: 10px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  h1 {
    font-size: 22px;
  }

  .primary-button {
    min-width: 96px;
    padding: 0 12px;
    font-size: 14px;
  }

  .details-panel {
    grid-template-columns: 1fr;
  }

  .score-strip {
    gap: 8px;
  }

  .score-card {
    min-height: 68px;
    padding: 10px;
  }

  .score-card strong {
    font-size: 24px;
  }

  .score-card small {
    max-width: 72px;
    font-size: 11px;
  }

  .avatar {
    width: 38px;
    height: 38px;
  }

  .board-wrap {
    padding: 8px;
    overflow: visible;
  }

  .board {
    width: min(100%, calc(100vw - 32px));
    min-width: 0;
  }

  .cell {
    padding: 1px;
    font-size: 5px;
    line-height: 1;
  }

  .cell.center::after {
    font-size: 14px;
  }

  .tile {
    border-radius: 4px;
    box-shadow: 0 2px 0 var(--tile-edge);
    font-size: 13px;
  }

  .tile small {
    right: 2px;
    bottom: 1px;
    font-size: 7px;
  }

  .rack-zone,
  .board-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .rack {
    width: 100%;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 6px;
  }

  .rack .tile {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }

  .turn-actions,
  .toolbar-actions {
    width: 100%;
  }

  .turn-actions button,
  .toolbar-actions button {
    flex: 1;
  }
}
