/* AI help: Claude Code wrote the styling around my .cell and color rules (2026-11-09) */
/* AI help: Claude Code restyled the board: big guess cell, smaller clue cells, clue labels, flip animation (2026-11-09) */
/* AI help: Claude created this skeleton file (imports only, no logic) (2026-11-01) */
/* AI help: Claude Code styled the feedback form and its Feedback label (2026-11-09) */
/* AI help: Claude Code replaced the bottom guess bar styles with an input that fills the guess cell (2026-11-09) */

/* ---------- Page ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

:root {
    --guess-cell-size: clamp(56px, calc(20vw - 2px), 68px);
    --clue-cell-size: clamp(44px, calc(15vw + 1px), 52px);
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #000;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
                 "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

/* Extra room at the bottom on phones so the board can scroll above the on-screen keyboard */
@media (pointer: coarse) {
    body { padding-bottom: 160px; }
}

/* ---------- Title + rules ---------- */

header {
    width: 100%;
    padding: 16px 16px 8px;
    text-align: center;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 0.2em;
    border-bottom: 1px solid #3a3a3c;
}

.tip {
    position: relative;
    max-width: 360px;
    margin: 8px 16px 12px;
    padding: 10px 34px 10px 12px;
    border-radius: 10px;
    background: #1c1c1e;
    font-size: 13px;
    line-height: 1.4;
    color: #c7c7cc;
    text-align: center;
}

.tip p { margin: 0; }

.tip button {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border: 0;
    background: none;
    color: #8e8e93;
    font-size: 14px;
    cursor: pointer;
}

.rules {
    max-width: 360px;
    margin: 8px 16px 16px;
    text-align: center;
    font-size: 12px;
    line-height: 1.4;
    color: #8e8e93;
}

/* ---------- Grid ---------- */
/* Cell sizes scale with the viewport while keeping the board within small phone widths. */

.row {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Guess cell: bigger square, extra gap after it so it reads "character + its clues" */
.row .cell:first-child {
    width: var(--guess-cell-size);
    height: var(--guess-cell-size);
    font-size: clamp(34px, 9vw, 40px);
    margin-right: 8px;
}

/* Clue cells: structure, part 1, part 2, strokes */
.row .cell:not(:first-child) {
    width: var(--clue-cell-size);
    height: var(--clue-cell-size);
    font-size: clamp(14px, 4vw, 18px);
}

/* ---------- Clue column labels ---------- */

.clue_labels {
    display: flex;
    width: max-content;
    padding-left: calc(var(--guess-cell-size) + 11px); /* align with the clue cells */
    margin-bottom: 2px;
}

.clue_labels span {
    display: inline-flex;
    width: var(--clue-cell-size);
    flex: 0 0 var(--clue-cell-size);
    height: 32px;
    margin: 3px;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: clamp(12px, 2.5vw, 14px);
    color: #8e8e93;
}

/* ---------- Flip animation when a cell gets a color ---------- */
/* Two animations: "flip" turns the cell, "flip_color" hides the new color
   until the cell is edge-on halfway through (150ms), so it flips into its color. */

.row .cell.green,
.row .cell.yellow,
.row .cell.grey {
    animation:
        flip 300ms ease-in-out backwards,
        flip_color 150ms step-end backwards;
}

.row .cell:nth-child(2) { animation-delay: 0ms; }
.row .cell:nth-child(3) { animation-delay: 150ms; }
.row .cell:nth-child(4) { animation-delay: 300ms; }
.row .cell:nth-child(5) { animation-delay: 450ms; }

@keyframes flip {
    0%   { transform: rotateX(0deg); }
    50%  { transform: rotateX(90deg); }
    100% { transform: rotateX(0deg); }
}

@keyframes flip_color {
    from { background-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
    .row .cell.green,
    .row .cell.yellow,
    .row .cell.grey {
        animation: none;
    }
}

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

#message {
    min-height: 28px;
    max-width: 360px;
    margin: 12px 16px;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
}

/* ---------- Share and stats ---------- */

#share_results {
    margin: 8px 16px 0;
    padding: 11px 16px;
    color: #fff;
    font: inherit;
    font-weight: 700;
    background: linear-gradient(135deg, #2f9e5a, #1f7a44);
    border: 1px solid #5fd08a;
    box-shadow: 0 4px 14px rgba(63, 185, 112, 0.3);
    border-radius: 9px;
    cursor: pointer;
}

#share_results:hover {
    background: linear-gradient(135deg, #38b468, #248a4e);
}

#stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 360px;
    margin: 12px 16px 0;
    padding: 12px;
    color: #ededf0;
    background: #0f1612;
    border: 1px solid #2f6b47;
    border-radius: 12px;
}

#stats[hidden],
#share_results[hidden],
#next_game_note[hidden] {
    display: none;
}

#stats > div {
    display: flex;
    min-height: 64px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px;
    color: #bcbcc4;
    font-size: 12px;
    font-weight: 600;
    background: #16211a;
    border: 1px solid #2a4a36;
    border-radius: 8px;
}

#stats span {
    color: #6ee79a;
    font-size: 24px;
    font-weight: 800;
    line-height: 1;
}

#next_game_note {
    margin: 8px 16px 0;
    color: #bcbcc4;
    font-size: 13px;
    text-align: center;
}

/* ---------- Answer card ---------- */

#answer_card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 32px);
    max-width: 340px;
    padding: 28px;
    text-align: center;
    font-size: 18px;
    line-height: 1.5;
    background-color: #121213;
    border: 1px solid #2f6b47;
    border-radius: 12px;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.6), 0 0 32px rgba(63, 185, 112, 0.18), 0 12px 40px rgba(0, 0, 0, 0.8);
    z-index: 10;
    animation: pop 200ms ease-out;
}

#answer_hanzi {
    margin-bottom: 10px;
    color: #dff2e3;
    font-size: 56px;
    font-weight: 700;
    line-height: 1.1;
}

#answer_pinyin {
    margin-bottom: 7px;
    color: #bfd9ef;
    font-size: 18px;
}

#answer_english {
    margin-bottom: 12px;
    color: #fff;
    font-size: 16px;
    font-weight: 400;
    overflow-wrap: anywhere;
}

/* Setting display/position above must not override the hidden attribute */
#answer_card[hidden] {
    display: none;
}

@keyframes pop {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    #answer_card {
        animation: none;
    }
}

/* ---------- View puzzle / show results ---------- */

#view_puzzle,
#show_results {
    margin: 12px auto 0;
    padding: 9px 16px;
    color: #6ee79a;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    background: transparent;
    border: 1px solid #2f6b47;
    border-radius: 9px;
    cursor: pointer;
}

#show_results {
    display: block;
}

#view_puzzle:hover,
#show_results:hover {
    background: #16211a;
}

#view_puzzle[hidden],
#show_results[hidden] {
    display: none;
}

/* ---------- Win celebration ---------- */

#win_banner {
    margin-bottom: 14px;
    color: #6ee79a;
    font-size: 22px;
    font-weight: 800;
    animation: banner_bounce 600ms ease-out;
}

#win_banner[hidden] {
    display: none;
}

#answer_card.won {
    border-color: #3fb970;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.6), 0 0 48px rgba(63, 185, 112, 0.35), 0 12px 40px rgba(0, 0, 0, 0.8);
}

.confetti_layer {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 20;
}

.confetti {
    position: absolute;
    top: -40px;
    font-size: 22px;
    animation: confetti_fall linear forwards;
}

.confetti_bit {
    width: 9px;
    height: 14px;
    border-radius: 2px;
}

@keyframes confetti_fall {
    to {
        transform: translate(var(--drift), 110vh) rotate(var(--spin));
        opacity: 0.9;
    }
}

@keyframes banner_bounce {
    0% { transform: scale(0.4); opacity: 0; }
    60% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    #win_banner {
        animation: none;
    }
}

/* ---------- Guess input (lives inside the current row's guess cell) ---------- */

.row .cell:has(#guess_input) {
    border-color: #d7d7df;
    box-shadow: 0 0 0 2px rgba(215, 215, 223, 0.22);
}

#guess_input {
    width: 100%;
    height: 100%;
    padding: 0;
    font-size: clamp(36px, 10vw, 42px); /* 16px or more stops iOS from zooming on focus */
    font-weight: bold;
    font-family: inherit;
    text-align: center;
    color: #fff;
    caret-color: #fff;
    background: transparent;
    border: none;
    outline: none;
}

.type_hint {
    margin: 10px 16px 0;
    font-size: 12px;
    color: #8e8e93;
    text-align: center;
}

/* ---------- Feedback form ---------- */

#feedback_form {
    margin-top: auto; /* keeps it at the bottom of the page */
    width: 100%;
    max-width: 420px;
    padding: 4px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.feedback_title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #8e8e93;
}

.feedback_row {
    display: flex;
    gap: 8px;
}

#feedback_text {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    font-size: 16px;
    font-family: inherit;
    color: #fff;
    background-color: #121213;
    border: 1px solid #3a3a3c;
    border-radius: 8px;
    outline: none;
    resize: none;
}

#feedback_text:focus {
    border-color: #8e8e93;
}

#feedback_form button {
    align-self: stretch;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    color: #fff;
    background-color: transparent;
    border: 1px solid #3a3a3c;
    border-radius: 8px;
    cursor: pointer;
}

#feedback_form button:hover {
    border-color: #8e8e93;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.shake {
  animation: shake 0.4s;
}

/* ---------- .cell and color rules ---------- */

.cell {
    width: 52px;
    height: 52px;
    display: inline-flex;
    font-size: 24px;
    align-items: center;
    border: 2px solid #686870;
    margin: 3px;
    color: #fff;
    justify-content: center;
    font-weight: 700;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    background-color: #111114;
}

.green {
    background-color: #287d37;
}

.grey {
    background-color: #484850;
}

.yellow {
    background-color: #806400;
}

/* ---------- Copy toast ---------- */

#copy_toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    z-index: 1000;
    padding: 10px 16px;
    color: #fff;
    font-weight: 700;
    background: #1f7a44;
    border: 1px solid #5fd08a;
    border-radius: 9px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translate(-50%, 12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

#copy_toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
    #copy_toast {
        transition: opacity 0.2s ease;
        transform: translate(-50%, 0);
    }
}
