/* WordInfinite - colours match the WinForms app (modGlobals.vb). All classes are prefixed "wi-". */

:root {
    --wi-bg: #000;
    --wi-panel: #282828;
    --wi-board: #7c7c7e;      /* colBoard - empty/typed tile */
    /* Tile colours: the player's choice (TileColors), set inline on .wi-app. These are the defaults (the
       "Lagoon" preset) until their saved colours load. Each has a matching readable text colour. */
    --wi-correct: #2a9d8f;    --wi-correct-text: #fff;
    --wi-present: #e76f51;    --wi-present-text: #fff;
    --wi-absent: #3e3e40;     --wi-absent-text: #fff;
    --wi-key: #909092;        /* colDefault - unused key */
    --wi-text: #fff;
    --wi-jumble-bg: #e6e6e6;
    --wi-jumble-text: #000;
    --wi-cursor: #e0e0e0;     /* Outline on the selected tile */
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--wi-bg);
    color: var(--wi-text);
    font-family: Arial, Helvetica, sans-serif;
}

body {
    touch-action: manipulation;      /* No double-tap zoom while typing fast */
    overscroll-behavior: none;       /* No pull-to-refresh mid-game */
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Layout: header, board (takes the spare space), message, keyboard ---------- */

.wi-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;                  /* Mobile: excludes the browser's address bar */
    max-width: 720px;
    margin: 0 auto;
    padding: env(safe-area-inset-top) 8px env(safe-area-inset-bottom);
    box-sizing: border-box;
    user-select: none;
}

.wi-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 2px;
    border-bottom: 1px solid #333;
}

.wi-header h1 {
    flex: 1;
    margin: 0;
    font-size: clamp(15px, 4.2vw, 22px);
    white-space: nowrap;
}

.wi-header h1:focus {
    outline: none;                   /* Blazor focuses the title on load for screen readers; no visible box */
}

.wi-mode {
    color: #aaa;
    font-weight: normal;
    font-size: 0.75em;
}

.wi-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
}

/* ---------- Board ---------- */

.wi-board-area {
    flex: 1 1 auto;
    min-height: 0;
    container-type: size;            /* Lets the board size itself to this box (cqw/cqh units) */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 0;
}

.wi-board {
    --gap: clamp(3px, 1.2cqmin, 6px);
    /* Biggest tile that fits both across and down, capped at 64px */
    --tile: min(
        calc((100cqw - (var(--cols) - 1) * var(--gap) - 8px) / var(--cols)),
        calc((100cqh - (var(--rows) - 1) * var(--gap) - 8px) / var(--rows)),
        64px);
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.wi-row {
    display: flex;
    gap: var(--gap);
}

.wi-tile {
    --wi-tile-bg: var(--wi-board);
    --wi-tile-fg: var(--wi-text);
    width: var(--tile);
    height: var(--tile);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border-radius: 3px;
    background-color: var(--wi-tile-bg);
    color: var(--wi-tile-fg);
    font-weight: bold;
    font-size: calc(var(--tile) * 0.55);
    cursor: pointer;
}

.wi-tile.wi-absent  { --wi-tile-bg: var(--wi-absent);  --wi-tile-fg: var(--wi-absent-text); }
.wi-tile.wi-present { --wi-tile-bg: var(--wi-present); --wi-tile-fg: var(--wi-present-text); }
.wi-tile.wi-correct { --wi-tile-bg: var(--wi-correct); --wi-tile-fg: var(--wi-correct-text); }
.wi-tile.wi-jumbled { --wi-tile-bg: var(--wi-jumble-bg); --wi-tile-fg: var(--wi-jumble-text); }

.wi-tile.wi-cursor {
    outline: 2px solid var(--wi-cursor);
    outline-offset: 2px;
}

/* Standard mode: tiles flip one after another, changing colour when edge-on */
.wi-tile.wi-reveal {
    animation: wi-flip 500ms ease-in-out backwards;  /* "backwards": show the start frame during the delay */
}

@keyframes wi-flip {
    0%    { transform: rotateX(0);     background-color: var(--wi-board); color: var(--wi-text); }
    50%   { transform: rotateX(90deg); background-color: var(--wi-board); color: var(--wi-text); }
    50.1% { background-color: var(--wi-tile-bg); color: var(--wi-tile-fg); }
    100%  { transform: rotateX(0);     background-color: var(--wi-tile-bg); color: var(--wi-tile-fg); }
}

/* Shakes: side to side for "not a word", up and down for No Forget (as the WinForms app) */
/* The duration (500ms) matches ShakeMs in Game.razor. The row wobbles and settles, and its tiles flash a red
   edge - so "not a word" is clear without reading the message. */
.wi-shake-h { animation: wi-shake-h 500ms ease-out; }
.wi-shake-v { animation: wi-shake-v 500ms ease-out; }
.wi-shake-h .wi-tile,
.wi-shake-v .wi-tile { animation: wi-refuse 500ms ease-out; }

@keyframes wi-shake-h {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-12px); }
    25% { transform: translateX(11px); }
    40% { transform: translateX(-8px); }
    55% { transform: translateX(6px); }
    70% { transform: translateX(-3px); }
    85% { transform: translateX(1px); }
}

@keyframes wi-shake-v {
    0%, 100% { transform: translateY(0); }
    10% { transform: translateY(-10px); }
    25% { transform: translateY(9px); }
    40% { transform: translateY(-6px); }
    55% { transform: translateY(4px); }
    70% { transform: translateY(-2px); }
}

@keyframes wi-refuse {
    0%, 60% { box-shadow: inset 0 0 0 3px #ff5252; }
    100% { box-shadow: inset 0 0 0 3px transparent; }
}

/* Reduced motion (e.g. Windows "Animation effects" off): no wobble or flip, but the red flash stays */
@media (prefers-reduced-motion: reduce) {
    .wi-tile.wi-reveal { animation-duration: 1ms; }
    .wi-shake-h, .wi-shake-v { animation: none; }
}

/* ---------- Message ---------- */

.wi-message {
    min-height: 2.6em;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: pre-line;
    font-weight: bold;
    font-size: clamp(14px, 3.8vw, 19px);
    padding: 0 4px;
}

/* ---------- Keyboard ---------- */

.wi-keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0 10px;
}

.wi-keyrow {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.wi-key {
    flex: 1 1 0;
    max-width: 52px;
    height: clamp(44px, 7.5dvh, 58px);
    padding: 0;
    border: none;
    border-radius: 5px;
    background: var(--wi-key);
    color: var(--wi-text);
    font-family: inherit;
    font-weight: bold;
    font-size: clamp(14px, 4vw, 19px);
    cursor: pointer;
}

.wi-key.wi-wide {
    flex-grow: 1.6;
    max-width: 84px;
    font-size: clamp(11px, 3vw, 14px);
}

.wi-key.wi-correct { background: var(--wi-correct); color: var(--wi-correct-text); }
.wi-key.wi-absent  { background: var(--wi-absent);  color: var(--wi-absent-text); }
.wi-key.wi-off,
.wi-key:disabled   { background: var(--wi-absent); color: #777; cursor: default; }

@media (hover: hover) {
    .wi-key:not(:disabled):hover { filter: brightness(1.15); }
}

/* ---------- Buttons ---------- */

.wi-btn {
    padding: 7px 11px;
    border: 1px solid #555;
    border-radius: 6px;
    background: #1c1c1c;
    color: var(--wi-text);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.wi-btn:disabled {
    cursor: default;                 /* Briefly disabled while a row flips - deliberately not dimmed, to avoid flicker */
}

.wi-btn-go {
    background: var(--wi-correct);
    border-color: var(--wi-correct);
    color: var(--wi-correct-text);
    font-weight: bold;
}

.wi-btn-danger { background: #a12a2a; border-color: #a12a2a; font-weight: bold; }

/* Account button in the header: a person icon, filled in the player's colour when signed in */
.wi-btn-icon { display: inline-flex; align-items: center; justify-content: center; padding: 6px 8px; }
.wi-btn-icon.wi-signed-in { color: var(--wi-correct); border-color: var(--wi-correct); }

/* "How to play" link in the header, styled as a button */
a.wi-btn { text-decoration: none; box-sizing: border-box; }
.wi-help { min-width: 34px; font-weight: bold; font-size: 16px; }

@media (hover: hover) {
    .wi-btn:not(:disabled):hover { filter: brightness(1.2); }
}

/* Header menu: Stats, Settings, How to play, Account. A plain row on wide screens; on narrow ones it
   folds into a drop-down behind the hamburger button, leaving New game/Give up always on show. */
.wi-header { position: relative; }
.wi-header h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; } /* The title gives way first */
.wi-menu { display: flex; align-items: center; gap: 6px; }
.wi-menu-toggle, .wi-menu-label, .wi-menu-backdrop { display: none; }

/* The dot on Daily (and on the menu button): one of today's daily puzzles isn't finished yet */
.wi-has-dot { position: relative; }
.wi-dot {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--wi-present);
    box-shadow: 0 0 0 2px var(--wi-bg);
    pointer-events: none;
}
.wi-menu-toggle .wi-dot { display: none; } /* Only shown on narrow screens, where Daily is hidden in the menu */

@media (max-width: 600px) {
    .wi-menu-toggle { display: inline-flex; }
    .wi-menu-toggle .wi-dot { display: block; }
    .wi-menu .wi-daily-btn { display: flex; align-items: center; }
    .wi-menu .wi-dot { position: static; margin-left: auto; box-shadow: none; }
    .wi-menu-backdrop { display: block; position: fixed; inset: 0; z-index: 5; }
    .wi-menu {
        display: none;
        position: absolute;
        top: calc(100% + 4px);
        right: 2px;
        z-index: 6;
        flex-direction: column;
        align-items: stretch;
        min-width: 170px;
        padding: 6px;
        background: var(--wi-panel);
        border: 1px solid #444;
        border-radius: 8px;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
    }
    .wi-menu.wi-menu-open { display: flex; }
    .wi-menu .wi-btn { justify-content: flex-start; gap: 8px; padding: 10px 12px; font-size: 15px; text-align: left; }
    .wi-menu .wi-help { font-weight: normal; }
    .wi-menu .wi-icon-text { display: none; }
    .wi-menu-label { display: inline; }
}

@media (max-width: 400px) {
    .wi-header { gap: 4px; }
}

/* ---------- Panels (settings, stats) ---------- */

.wi-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
}

.wi-modal {
    width: min(440px, calc(100vw - 20px));
    max-height: calc(100dvh - 20px);
    overflow: auto;
    box-sizing: border-box;
    padding: 16px;
    border: 2px solid #d3d3d3;
    border-radius: 8px;
    background: var(--wi-panel);
    user-select: text;
}

.wi-modal h2 { margin: 0 0 12px; font-size: 20px; }
.wi-modal h3 { margin: 16px 0 8px; font-size: 15px; }

.wi-hint { color: #bbb; font-size: 13px; margin: 6px 0 10px; }
.wi-warning { color: #e8c65a; font-size: 13px; margin: 10px 0; }

.wi-segmented { display: flex; gap: 6px; margin-bottom: 10px; }
.wi-segmented button,
.wi-lists button {
    flex: 1;
    padding: 9px;
    border: 1px solid #555;
    border-radius: 6px;
    background: #1c1c1c;
    color: #ccc;
    font: inherit;
    cursor: pointer;
}
.wi-segmented button.wi-on,
.wi-lists button.wi-on { background: var(--wi-correct); border-color: var(--wi-correct); color: var(--wi-correct-text); font-weight: bold; }

.wi-lists { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.wi-lists button { flex: 0 1 auto; }

.wi-options { display: flex; flex-direction: column; gap: 8px; padding: 6px 0; }
.wi-options.wi-dim { opacity: 0.45; }

.wi-option { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.wi-option input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--wi-correct); flex-shrink: 0; }
.wi-option span { display: flex; flex-direction: column; }
.wi-option small { color: #aaa; font-size: 12px; margin-top: 2px; }

.wi-setting-row { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 4px; }

.wi-stepper { display: flex; align-items: center; gap: 10px; }
.wi-stepper span { min-width: 2ch; text-align: center; font-size: 20px; font-weight: bold; }
.wi-stepper button {
    width: 40px; height: 40px;
    border: 1px solid #555; border-radius: 6px;
    background: #1c1c1c; color: #fff;
    font-size: 22px; cursor: pointer;
}
.wi-stepper button:disabled { opacity: 0.35; cursor: default; }

.wi-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.wi-spacer { flex: 1; }

.wi-stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.wi-stat-grid div { display: flex; flex-direction: column; }
.wi-stat-grid b { font-size: 26px; }
.wi-stat-grid span { font-size: 12px; color: #bbb; }

.wi-bars { display: flex; flex-direction: column; gap: 4px; }
.wi-bar-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.wi-bar-row > span { width: 1ch; }
.wi-bar {
    min-width: 2ch;
    padding: 2px 6px;
    box-sizing: border-box;
    background: var(--wi-absent);
    color: var(--wi-absent-text);
    text-align: right;
    font-weight: bold;
}

/* ---------- Tile colours (settings) ---------- */

.wi-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.wi-preset {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 9px;
    border: 1px solid #555; border-radius: 6px;
    background: #1c1c1c; color: #ccc;
    font: inherit; font-size: 13px; cursor: pointer;
}
.wi-preset.wi-on { border-color: #fff; color: #fff; font-weight: bold; }
.wi-preset-custom { cursor: default; opacity: 0.6; }
.wi-preset-custom.wi-on { opacity: 1; }
.wi-swatches { display: inline-flex; gap: 2px; }
.wi-swatches i { display: block; width: 12px; height: 12px; border-radius: 2px; }

.wi-color-picks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0; font-size: 13px; color: #ccc; }
.wi-color-picks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.wi-color-picks input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid #555; border-radius: 4px; background: none; cursor: pointer; }

.wi-color-preview { display: flex; gap: 4px; --tile: 34px; }
.wi-color-preview .wi-tile { cursor: default; }

/* ---------- Account ---------- */

.wi-form { display: flex; flex-direction: column; gap: 10px; }
.wi-form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.wi-form label small { color: #999; font-size: 12px; }
.wi-form input {
    padding: 9px 10px;
    border: 1px solid #555; border-radius: 6px;
    background: #1c1c1c; color: #fff;
    font: inherit; font-size: 16px;   /* 16px stops phones zooming in on focus */
}
.wi-form input:focus { outline: 2px solid var(--wi-correct); outline-offset: 0; }
.wi-error { color: #ff8a80; font-size: 14px; margin: 0; }

/* ---------- Today's puzzles (daily panel) ---------- */

.wi-daily-list { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 12px; }
.wi-daily-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #1c1c1c;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
}
.wi-daily-name { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wi-daily-name b { font-size: 16px; }
.wi-daily-name span { font-size: 12px; color: #aaa; }
.wi-daily-result { font-size: 14px; font-weight: bold; color: #bbb; white-space: nowrap; }
.wi-daily-result.wi-won { color: var(--wi-correct); }
.wi-daily-row .wi-btn { min-width: 76px; }
.wi-account-name { color: var(--wi-correct); }
.wi-notice { padding: 8px 10px; border-left: 3px solid var(--wi-correct); background: #1c1c1c; font-size: 14px; margin: 0 0 12px; }

/* A button that looks like a link ("Forgot password?") */
.wi-link {
    padding: 0; border: none; background: none;
    color: #9ecbff; font: inherit; font-size: 14px; text-decoration: underline;
    cursor: pointer;
}

/* ---------- Jumbled-columns board ---------- */

/* Fewer rows than the word board, so the tiles may grow bigger */
.wi-board.wi-cols-board {
    --tile: min(
        calc((100cqw - (var(--cols) - 1) * var(--gap) - 8px) / var(--cols)),
        calc((100cqh - (var(--rows) - 1) * var(--gap) - 8px) / var(--rows)),
        84px);
}

.wi-cell { position: relative; transition: background-color 120ms; }
.wi-cell.wi-claimed { box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25); }
.wi-cell.wi-miss { opacity: 0.45; }

/* The colour's number in the tile's corner, so colours never have to be told apart by eye */
.wi-badge {
    position: absolute; top: 2px; left: 4px;
    font-size: max(10px, calc(var(--tile) * 0.22)); line-height: 1; font-weight: bold;
    opacity: 0.85;
}

.wi-cols-controls { padding: 4px 0 calc(8px + env(safe-area-inset-bottom)); }

/* Bar above the colour buttons: which word is being spelled, and its letters so far */
.wi-active-word {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 8px; padding: 6px 10px;
    border-radius: 8px;
    transition: background-color 150ms;
}
.wi-active-label { font-weight: bold; font-size: 16px; white-space: nowrap; }
.wi-active-letters { display: flex; gap: 4px; margin-left: auto; }
.wi-active-letter {
    width: 26px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.22);
    font-weight: bold; font-size: 18px;
}

.wi-word-colors { display: flex; gap: 6px; }
.wi-word-color {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 2px;
    border: 3px solid transparent; border-radius: 8px;
    font: inherit; cursor: pointer;
}
.wi-word-color b { font-size: 20px; line-height: 1; }
.wi-word-color small { font-size: 11px; letter-spacing: 1px; font-family: Consolas, "Courier New", monospace; white-space: nowrap; }
.wi-word-color.wi-on { border-color: #fff; box-shadow: 0 0 0 2px #000 inset; transform: translateY(-2px); }

.wi-cols-controls .wi-actions { margin-top: 10px; }

.wi-cols-results { display: flex; flex-direction: column; gap: 4px; }
.wi-result { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.wi-result.wi-miss { color: #999; }
.wi-result-word { font-family: Consolas, "Courier New", monospace; font-size: 17px; letter-spacing: 2px; min-width: 7ch; }
.wi-word-swatch {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 4px; font-weight: bold; font-size: 14px; flex-shrink: 0;
}
.wi-cols-results .wi-hint { margin: 6px 0 0; }
