@font-face {
  font-family: 'Open Sans';
  src: url('../fonts/OpenSans-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Open Sans Bold';
  src: url('../fonts/OpenSans-Bold.ttf') format('truetype');
}
@font-face {
  font-family: 'Courier Prime';
  src: url('../fonts/CourierPrime-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Courier Prime Bold';
  src: url('../fonts/CourierPrime-Bold.ttf') format('truetype');
}
@font-face {
  font-family: 'Courier Prime Italic';
  src: url('../fonts/CourierPrime-Italic.ttf') format('truetype');
}
@font-face {
  font-family: 'Courier Prime Bold Italic';
  src: url('../fonts/CourierPrime-BoldItalic.ttf') format('truetype');
}

body {
    font-family: "Open Sans", Arial, Tahoma, Geneva, sans-serif;
    margin: 0;
    padding: 0;
    color: #555;
    font-size: 1rem;
    /* Stops iOS/Android from bumping text up a size in landscape. */
    -webkit-text-size-adjust: 100%;
}

form {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem 1.25rem 3rem;
    box-sizing: border-box;
}

h1 {
    font-size: 2em;
    line-height: 1.75em;
    margin-bottom: 0.2em;
    text-align: center;
    color: #45c03f;
    background-color: #000;
}

h2 {
    font-size: 1.5em;
}

p {
    line-height: 1.5em;
}

a {
    color: SteelBlue;
}

a:hover {
    color: #36658c;
}

input[type="text"], input[type="email"], input[type="password"], select {
    padding: 0.6em 0.6em;
    font-size: 1em;
    border: 1px #333 solid;
    box-sizing: border-box;
}

input[type="text"]:focus, textarea:focus, input[type="email"]:focus, input[type="password"]:focus, select:focus {
    border: 1px SteelBlue solid;
    outline: 0;
}

input[type="text"], input[type="email"], input[type="password"], button, textarea, select {
    border-radius: 6px;
}

textarea {
    padding: 0.6em 0.6em;
    font-size: 1.231em;
    width: 100%;
    height: 100%; 
    box-sizing: border-box;
    border: 1px #333 solid; 
    line-height: 1.6em;       
}

label {
    margin: 1.4em 0 0.4em 1em;
    font-weight: bold;
    clear: both;
    display: inline-block;
}

button {
    background-color: SteelBlue;
    border: 1px SteelBlue solid;
    margin: 0;
    padding: 0.6em 1.2em;
    color: #fff;
    font-size: 0.9em;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    /* 44px is the minimum comfortable touch target on iOS/Android. */
    min-height: 44px;
    touch-action: manipulation;
}

button:hover {
    background-color: #36658c;
    border: 1px #36658c solid;
}

button:focus-visible,
select:focus-visible {
    outline: 3px solid #ffb300;
    outline-offset: 2px;
}

/* Hover styling is a lie on touch screens -- it sticks after a tap. Only
   apply the colour change where a real pointer can hover. */
@media (hover: none) {
    button:hover {
        background-color: SteelBlue;
        border-color: SteelBlue;
    }
    button:active {
        background-color: #36658c;
        border-color: #36658c;
    }
}

.alt {
    background-color: transparent;
    border: 1px SteelBlue solid;
    color: #333;        
}

.alt:hover {
    background-color: transparent;
    border: 1px #36658c solid;
    color: SteelBlue;
}

ul {
    margin: 2em 0;
    list-style-type: circle;
}

li {
    line-height: 1.8em;
}

input[type="checkbox"] {
  top: 0.3em;
  position: relative;
  width: 1.4em; height: 1.4em;
}

input[type="radio"] {
    margin: 1.6em 0 2em 1em;
}

hr {
    border: 0;
    height: 1px;
    background: #555;
    margin: 2em 0;
}

/* Application specific CSS */

/* Board metrics derive from one value. vmin keeps the grid proportional to the
   shorter screen edge, so it grows on a tablet in either orientation without
   ever pushing the keypad below the fold. */
:root {
    --cell: clamp(44px, 17vmin, 90px);
    --cell-border: 3px;
    --board-w: 34rem;
}

header {
    display: block;
    margin: 0 0 1rem;
    font-family: "Open Sans Bold", Arial, Tahoma, Geneva, sans-serif;
    font-size: clamp(1.4rem, 4.5vw, 2rem);
    font-weight: bold;
    color: #333;
}

/* Toolbars: controls flow onto as many rows as they need instead of running
   off the edge, and every control shares a baseline. */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    margin: 0 0 1.5rem;
}

.toolbar-bottom {
    margin: 1.5rem 0 0;
}

.field {
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0;
    font-weight: normal;
}

.field-label {
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #777;
}

.field-row {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar select {
    min-height: 44px;
}

.meta {
    align-self: center;
    font-size: 0.9rem;
    color: #666;
}

/* This stylesheet predates a global border-box reset, so padding and borders
   would otherwise sit outside every flex-basis and silently overflow the line. */
.game,
.board,
.keypad,
.instructions,
.toolbar {
    box-sizing: border-box;
}

.game {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1.5rem 2rem;
    font-family: "Courier Prime", monotype;
}

/* A definite width gives the keypad's `width: 100%` something real to resolve
   against. min-width: 0 is the standard flex escape hatch -- without it the
   item's automatic minimum size is its min-content, which here is wide enough
   to push the instructions onto their own row even when they would fit. */
.board {
    flex: 0 1 var(--board-w);
    width: var(--board-w);
    max-width: 100%;
    min-width: 0;
}

.puzzle {
    border-collapse: collapse;
    caret-color: transparent;
    font-size: calc(var(--cell) * 0.5);
}

.game tbody td {
    text-align: center;
    border: solid #ccc var(--cell-border);
    height: var(--cell);
    width: var(--cell);
    padding: 0;
}

/* Reserve the gutter up front so a check or cross appearing does not shove the
   board sideways mid-game. */
.game tbody td.verify {
    border: solid transparent var(--cell-border);
    height: auto;
    /* Sized in its own em so the tick scales with the board. */
    font-size: 0.75em;
    width: 1.4em;
    min-width: 1.4em;
}

.game tbody td.grid {
    background-color: #f5f5f5;
}

.game tbody td input[type="text"] {
    display: block;
    padding: 0;
    margin: 0;
    font-family: "Courier Prime", monotype;
    font-size: 1em;
    text-align: center;
    color: inherit;
    background: transparent;
    border: none;
    outline: none;
    /* Was `box-sizing: auto`, which is invalid -- the declaration was dropped and
       the padding pushed the input past the cell it lived in. */
    box-sizing: border-box;
    border-radius: 0;
    height: 100%;
    width: 100%;
}

input[type="text"]#word {
    width: 5em;
    min-height: 44px;
}

.game tbody td:has(input[type="text"]:focus) {
    background-color: orange;
}

.game tbody td input[type="text"]:focus {
    border: none;
    outline: none;
    background-color: orange;
}

.game tbody td.grid {
    color: royalblue;
}

.game tbody td.error {
    background-color: #f99;
}

.game tbody td.solved,
.game tbody td.solved input[type="text"] {
    background-color: #9f9;
}

/* On-screen letter pad. 27 keys over 9 columns is exactly 3 even rows; on a
   phone that would put each key under the 44px touch minimum, so it drops to 6. */
.keypad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0.4rem;
    margin: 1.25rem 0 0;
    width: 100%;
}

@media screen and (max-width: 520px) {
    .keypad {
        grid-template-columns: repeat(6, 1fr);
    }
}

.keypad .key {
    font-family: "Courier Prime", monotype;
    font-size: 1.1rem;
    font-weight: bold;
    padding: 0.5rem 0;
    min-height: 44px;
    background-color: #fff;
    border: 1px solid #bbb;
    color: #333;
    border-radius: 6px;
    /* Stops a double-tap on the pad zooming the page on iOS. */
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.keypad .key:hover {
    background-color: #eef4f9;
    border-color: SteelBlue;
    color: #333;
}

.keypad .key:active {
    background-color: SteelBlue;
    border-color: SteelBlue;
    color: #fff;
}

.keypad .key-delete {
    background-color: #f4f4f4;
    font-size: 1.2rem;
}

@media (hover: none) {
    .keypad .key:hover {
        background-color: #fff;
        border-color: #bbb;
    }
}

.instructions {
    flex: 1 1 16rem;
    margin: 0;
    font-size: 0.95rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    background: #fafafa;
}

.instructions summary {
    font-family: "Open Sans Bold", Arial, Tahoma, Geneva, sans-serif;
    font-weight: bold;
    cursor: pointer;
    padding: 0.25rem 0;
    min-height: 24px;
    color: #333;
}

.instructions p {
    font-family: "Open Sans", Arial, Tahoma, Geneva, sans-serif;
    margin: 0.75em 0 0;
}

/* Below the board on narrow screens; beside it once there is room. */
@media screen and (min-width: 700px) {
    .instructions {
        margin-top: 0;
    }
    .instructions[open] summary {
        margin-bottom: 0.25rem;
    }
}

/* Solutions overlay. Sits above the board rather than pushing it down the page,
   which on a tablet used to shove the grid off screen the moment you opened it. */
.solutions-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.55);
    box-sizing: border-box;
}

/* `display: flex` above would otherwise defeat the hidden attribute. */
.solutions-overlay[hidden] {
    display: none;
}

.solutions-panel {
    display: flex;
    flex-direction: column;
    width: min(56rem, 100%);
    max-height: 100%;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
    overflow: hidden;
}

.solutions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    border-bottom: 1px solid #ddd;
    flex: 0 0 auto;
}

.solutions-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: #333;
}

.solutions-close {
    background: transparent;
    border: none;
    color: #555;
    font-size: 1.75rem;
    line-height: 1;
    padding: 0 0.6rem;
    min-width: 44px;
    border-radius: 6px;
}

.solutions-close:hover {
    background: #eee;
    border: none;
    color: #000;
}

.solutions-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 0.75rem;
}

.solution {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    font-family: "Courier Prime", monotype;
    font-size: 0.8rem;
    padding: 0.5rem;
    border: solid #ddd 1px;
    border-radius: 6px;
    background: #fafafa;
}

/* .solution reuses the board's .puzzle class, which carries the full cell-sized
   font. Reset it so these read as a reference list, not eight more game boards. */
.solution .puzzle {
    font-size: 1em;
}

/* Every card is captioned "Solution" inside a panel already titled Solutions. */
.solution .puzzle thead {
    display: none;
}

.solution table {
    padding: 0;
}

.solution td,
.solution th {
    padding: 0.1rem 0.35rem;
    text-align: center;
}

.solution .words th {
    font-weight: bold;
    color: #777;
    font-size: 0.9em;
}

.error {
    color: red;
}

.success {
    color: green;
}

.big {
    font-size: 1em;
}

/* Covers the page while the solver works. Above the solutions overlay (200) so
   that switching difficulty from an open solutions panel still reads correctly. */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.94);
    text-align: center;
    box-sizing: border-box;
}

.loading-overlay img {
    max-width: min(60vw, 320px);
    height: auto;
}

.loading-overlay p {
    margin: 0;
    font-family: "Open Sans Bold", Arial, Tahoma, Geneva, sans-serif;
    font-weight: bold;
    color: #555;
}

#winner {
    display: none;
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: min(800px, 92vw);
    z-index: 100;
}
