/* Word Tiles - self-contained styling. The widget root carries ".wt-game"
   plus a data-theme attribute; dark mode follows the OS by default (theme
   "auto") or can be forced with theme="light"/"dark" on the shortcode. */

.wt-game {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #d8dbe2;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --board-bg: #a8c9b8;
  --cell-bg: #e9ede9;
  --cell-border: #c7d0c8;
  --dl-bg: #bcdcf0;
  --dl-text: #1a5f85;
  --tl-bg: #4f9fd6;
  --tl-text: #ffffff;
  --dw-bg: #f3c6c6;
  --dw-text: #8a2e2e;
  --tw-bg: #dd6b6b;
  --tw-text: #ffffff;
  --star-bg: #f3c6c6;
  --tile-bg: #f1d9a0;
  --tile-border: #b9905a;
  --tile-text: #3a2c14;
  --tile-pending-bg: #ffe9a8;
  --tile-pending-border: #d6a53a;
  --key: #eceef2;
  --key-edge: #c3c7d1;

  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  border-radius: 14px;
  padding: 8px;
  box-sizing: border-box;
}
.wt-game, .wt-game *, .wt-game *::before, .wt-game *::after { box-sizing: border-box; }
.wt-game button { font-family: inherit; cursor: pointer; }

@media (prefers-color-scheme: dark) {
  .wt-game[data-theme="auto"] {
    --bg: #14161c; --surface: #1c1f28; --surface-2: #262b36; --border: #3a4150;
    --text: #eef0f4; --muted: #9aa1ae; --accent: #8b85f6; --accent-text: #12131a;
    --board-bg: #223428; --cell-bg: #1d2621; --cell-border: #33413a;
    --dl-bg: #204a5c; --dl-text: #bfe6fb;
    --tl-bg: #235f8a; --tl-text: #ffffff;
    --dw-bg: #5c2a2a; --dw-text: #f6c8c8;
    --tw-bg: #7a2a2a; --tw-text: #ffffff;
    --star-bg: #5c2a2a;
    --tile-bg: #d9b876; --tile-border: #8a6a35; --tile-text: #2a2010;
    --tile-pending-bg: #e9cb6a; --tile-pending-border: #a8842f;
    --key: #2f3542; --key-edge: #12141a;
  }
}
.wt-game[data-theme="dark"] {
  --bg: #14161c; --surface: #1c1f28; --surface-2: #262b36; --border: #3a4150;
  --text: #eef0f4; --muted: #9aa1ae; --accent: #8b85f6; --accent-text: #12131a;
  --board-bg: #223428; --cell-bg: #1d2621; --cell-border: #33413a;
  --dl-bg: #204a5c; --dl-text: #bfe6fb;
  --tl-bg: #235f8a; --tl-text: #ffffff;
  --dw-bg: #5c2a2a; --dw-text: #f6c8c8;
  --tw-bg: #7a2a2a; --tw-text: #ffffff;
  --star-bg: #5c2a2a;
  --tile-bg: #d9b876; --tile-border: #8a6a35; --tile-text: #2a2010;
  --tile-pending-bg: #e9cb6a; --tile-pending-border: #a8842f;
  --key: #2f3542; --key-edge: #12141a;
}

.wt-wrap { max-width: 920px; margin: 0 auto; padding: 22px 20px 26px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }

.wt-header { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.wt-title { font-family: 'Baloo 2', 'IBM Plex Sans', sans-serif; font-weight: 800; font-size: 1.7rem; margin: 0 0 4px; letter-spacing: .01em; }
.wt-tag { margin: 0 auto; color: var(--muted); font-size: .92rem; max-width: 52ch; }
.wt-controls-row { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.wt-diff-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.wt-diff-select {
  font-family: inherit; font-size: .88rem; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
}

.wt-btn {
  font-family: inherit; font-weight: 600; font-size: .85rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; transition: background-color .15s ease;
}
.wt-btn:hover:not(:disabled) { background: var(--border); }
.wt-btn:disabled { opacity: .5; cursor: default; }
.wt-btn.wt-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.wt-btn.wt-primary:hover:not(:disabled) { filter: brightness(1.06); }

.wt-scoreboard { display: flex; justify-content: center; gap: 28px; margin-bottom: 18px; flex-wrap: wrap; }
.wt-score-card { text-align: center; padding: 8px 18px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); min-width: 120px; }
.wt-score-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }

@keyframes wt-flash-you {
  0%, 100% { border-color: var(--border); box-shadow: none; background: var(--surface-2); }
  50% { border-color: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, .45); background: rgba(34, 197, 94, .18); }
}
@keyframes wt-flash-cpu {
  0%, 100% { border-color: var(--border); box-shadow: none; background: var(--surface-2); }
  50% { border-color: #a855f7; box-shadow: 0 0 0 4px rgba(168, 85, 247, .45); background: rgba(168, 85, 247, .18); }
}
.wt-score-card.wt-flash-you { animation: wt-flash-you .5s ease-in-out 3; }
.wt-score-card.wt-flash-cpu { animation: wt-flash-cpu .5s ease-in-out 3; }

/* Game-over: drop the now-useless play controls so only the board, score, and log remain. */
.wt-game.wt-over .wt-rack-label,
.wt-game.wt-over .wt-rack,
.wt-game.wt-over .wt-potential,
.wt-game.wt-over .wt-actions,
.wt-game.wt-over .wt-suggestions,
.wt-game.wt-over .wt-hint {
  display: none;
}
.wt-score-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.wt-score-value { font-size: 1.5rem; font-weight: 800; font-family: 'Baloo 2', 'IBM Plex Sans', sans-serif; }
.wt-bag-count { text-align: center; font-size: .8rem; color: var(--muted); margin: 0 0 16px; }

.wt-stage { display: flex; gap: 24px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }

.wt-board-col { flex: 0 0 auto; }
.wt-board {
  display: grid;
  grid-template-columns: repeat(15, minmax(22px, 34px));
  grid-template-rows: repeat(15, minmax(22px, 34px));
  gap: 2px;
  background: var(--board-bg);
  padding: 6px;
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .18);
  user-select: none;
}
.wt-cell {
  position: relative;
  background: var(--cell-bg);
  border: 1px solid var(--cell-border);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .58rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  aspect-ratio: 1 / 1;
}
.wt-cell.wt-dl { background: var(--dl-bg); color: var(--dl-text); }
.wt-cell.wt-tl { background: var(--tl-bg); color: var(--tl-text); }
.wt-cell.wt-dw { background: var(--dw-bg); color: var(--dw-text); }
.wt-cell.wt-tw { background: var(--tw-bg); color: var(--tw-text); }
.wt-cell.wt-star { background: var(--star-bg); color: var(--dw-text); font-size: .95rem; }
.wt-cell.wt-target { outline: 2px solid var(--accent); outline-offset: -2px; }
.wt-cell.wt-hover-ok { background: color-mix(in srgb, var(--accent) 30%, var(--cell-bg)); }

.wt-tile {
  position: absolute; inset: 1px;
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--tile-text);
  font-size: .95rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.5);
  cursor: default;
}
.wt-tile.wt-pending { background: var(--tile-pending-bg); border-color: var(--tile-pending-border); cursor: pointer; }
.wt-tile.wt-pending:hover { filter: brightness(1.04); }
.wt-tile .wt-pts {
  position: absolute; bottom: 1px; right: 2px; font-size: .5rem; font-weight: 700; opacity: .75;
}
.wt-tile.wt-blank .wt-letter { font-style: italic; }
@media (max-width: 640px) {
  .wt-board { grid-template-columns: repeat(15, minmax(18px, 26px)); grid-template-rows: repeat(15, minmax(18px, 26px)); }
  .wt-tile { font-size: .78rem; }
  /* Tiles are tiny on a phone screen, so the point-value badge overlaps and
     obscures the letter. Hide it on placed board tiles only; the rack tiles
     (fixed, larger size) still show their value. */
  .wt-tile .wt-pts { display: none; }
}

.wt-side-col { flex: 1 1 260px; min-width: 240px; max-width: 340px; }
.wt-message { min-height: 3.2em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: .86rem; margin-bottom: 14px; }
.wt-message.wt-good { border-color: var(--accent); }
.wt-message.wt-bad { color: #c0392b; }
.wt-log { max-height: 160px; overflow-y: auto; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.wt-log div { padding: 2px 0; }

.wt-rack-label { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; text-align: center; }
.wt-rack {
  display: flex; justify-content: center; gap: 6px; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; margin-bottom: 12px; min-height: 60px;
}
.wt-rack-tile {
  position: relative;
  width: 40px; height: 40px;
  background: var(--tile-bg); border: 1px solid var(--tile-border); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--tile-text); font-size: 1.1rem;
  box-shadow: 0 2px 3px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.5);
  transition: transform .1s ease;
}
.wt-rack-tile.wt-selected { transform: translateY(-6px); box-shadow: 0 6px 8px rgba(0,0,0,.3); outline: 2px solid var(--accent); }
.wt-rack-tile .wt-pts { position: absolute; bottom: 1px; right: 3px; font-size: .55rem; font-weight: 700; opacity: .75; }
.wt-rack-tile.wt-exch-marked { outline: 2px solid #c0392b; }

.wt-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.wt-hint { text-align: center; color: var(--muted); font-size: .8rem; margin: 6px 0 0; }

.wt-potential {
  text-align: center; margin: 0 0 12px; font-size: .88rem; font-weight: 700; color: var(--muted);
  min-height: 1.3em; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.wt-potential.wt-potential-ready {
  color: var(--accent-text); background: var(--accent); border-color: var(--accent);
  font-size: .95rem;
}

.wt-suggestions {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; margin: 0 0 12px; display: flex; flex-direction: column; gap: 4px;
}
.wt-suggestions[hidden] { display: none; }
.wt-suggestion-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: .84rem; cursor: pointer; text-align: left;
  font-family: inherit; color: var(--text);
}
.wt-suggestion-row:hover { background: var(--border); }
.wt-suggestion-row .wt-sugg-word { font-weight: 700; letter-spacing: .03em; }
.wt-suggestion-row .wt-sugg-pts { color: var(--muted); font-size: .8rem; }
.wt-suggestions-empty { text-align: center; color: var(--muted); font-size: .82rem; padding: 6px; }

.wt-blank-picker-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.wt-blank-picker {
  background: var(--surface, #fff); color: var(--text, #1a1a1a); border: 1px solid var(--border, #ccc);
  border-radius: 12px; padding: 18px; max-width: 320px; box-shadow: 0 12px 36px rgba(0,0,0,.45);
}
.wt-blank-picker p { margin: 0 0 12px; text-align: center; font-weight: 700; color: var(--text, #1a1a1a); }
.wt-blank-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.wt-blank-grid button {
  width: 38px; height: 38px; border-radius: 6px; border: 1px solid var(--tile-border, #b8860b);
  background: var(--tile-bg, #f4d999); color: var(--tile-text, #3a2c00); font-weight: 800; font-size: .95rem;
  cursor: pointer;
}
.wt-blank-grid button:hover { filter: brightness(1.08); }

.wt-footer { text-align: center; color: var(--muted); font-size: .76rem; margin: 20px 0 0; }
.wt-stats { text-align: center; color: var(--muted); font-size: .82rem; margin: 6px 0 0; }

.wt-game.pre .wt-stage { visibility: hidden; }

@media (max-width: 900px) {
  .wt-stage { flex-direction: column; align-items: center; }
  .wt-side-col { max-width: 100%; width: 100%; }
}
