/* ==========================================================================
   One Line Draw — Single Line Drawing Puzzle Game
   Stylesheet
   ========================================================================== */

:root {
    --bg-1:           #1b2a4a;
    --bg-2:           #2d4373;
    --board:          #f4ead5;
    --board-shadow:   rgba(0, 0, 0, 0.25);
    --line-pending:   #c8b99c;
    --line-drawn:     #ff7849;
    --line-active:    #ffb648;
    --node:           #2c3e63;
    --node-active:    #ff7849;
    --node-done:      #5fb86b;
    --text:           #ffffff;
    --accent:         #ffb648;
    --danger:         #ff5470;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
    color: var(--text);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
}

/* ==========================================================================
   Layout
   ========================================================================== */

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 720px;
    margin: 0 auto;
    position: relative;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: max(14px, env(safe-area-inset-top)) 18px 12px;
    flex-shrink: 0;
}

.title { text-align: center; }
.level-label {
    font-size: 10px;
    letter-spacing: 2.5px;
    opacity: 0.55;
}
.level-name {
    font-size: 17px;
    font-weight: 800;
    line-height: 1.1;
    margin-top: 3px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stage {
    flex: 1 1 auto;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    min-height: 0;
    min-width: 0;
}

#board {
    width: 100%;
    height: 100%;
    background: var(--board);
    border-radius: 24px;
    box-shadow: 0 14px 40px var(--board-shadow);
    touch-action: none;
    cursor: pointer;
}

.bottombar {
    padding: 10px 22px max(16px, env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover  { background: rgba(255, 255, 255, 0.16); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg    { width: 22px; height: 22px; }

.preview-btn {
    background: rgba(95, 184, 107, 0.2);
    color: var(--node-done);
}
.preview-btn:hover    { background: rgba(95, 184, 107, 0.32); }
.preview-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.primary-btn {
    background: var(--accent);
    color: #1b2a4a;
    border: none;
    font-weight: 700;
    font-size: 16px;
    padding: 14px 32px;
    border-radius: 999px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 6px 16px rgba(255, 182, 72, 0.35);
}
.primary-btn:hover  { box-shadow: 0 8px 22px rgba(255, 182, 72, 0.5); }
.primary-btn:active { transform: scale(0.96); }

.ghost-btn {
    background: transparent;
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 10px 24px;
    border-radius: 999px;
    cursor: pointer;
    margin-top: 18px;
    font-size: 13px;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.06); }

/* ==========================================================================
   Hint, preview banner, HUD
   ========================================================================== */

.hint {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: rgba(0, 0, 0, 0.45);
    background: rgba(244, 234, 213, 0.85);
    padding: 6px 14px;
    border-radius: 999px;
    white-space: nowrap;
    pointer-events: none;
    transition: opacity 0.4s;
}
.hint.fade { opacity: 0; }

.preview-banner {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 22, 40, 0.85);
    color: #fff;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    animation: popUp 0.25s ease;
}
.preview-banner.hidden { display: none; }
.preview-track {
    width: 80px;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    overflow: hidden;
}
.preview-bar {
    height: 100%;
    width: 0%;
    background: var(--node-done);
    border-radius: 999px;
}

.progress-track {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--line-drawn));
    border-radius: 999px;
    transition: width 0.25s ease;
}
.counter {
    font-size: 12px;
    opacity: 0.75;
    min-width: 60px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Overlays — win, menu
   ========================================================================== */

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 22, 40, 0.72);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    animation: fadeIn 0.25s ease;
}
.overlay.hidden { display: none; }

.overlay-card {
    background: linear-gradient(160deg, #2c3e63, #1b2a4a);
    border-radius: 20px;
    padding: 32px 28px;
    text-align: center;
    width: min(360px, 88%);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1);
}
.overlay-card h2 { margin: 0 0 8px; font-size: 26px; }
.overlay-card p  { margin: 0 0 22px; opacity: 0.7; font-size: 14px; }

.confetti {
    font-size: 44px;
    color: var(--accent);
    margin-bottom: 8px;
    animation: spin 1.4s ease-in-out infinite;
    display: inline-block;
}

.menu-card { width: min(420px, 92%); }
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 8px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 4px;
}
.level-cell {
    aspect-ratio: 1;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: var(--text);
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.level-cell:hover  { background: rgba(255, 255, 255, 0.16); }
.level-cell:active { transform: scale(0.94); }
.level-cell.done {
    background: var(--node-done);
    color: #fff;
}
.level-cell.current {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}
.level-cell.locked {
    background: rgba(0, 0, 0, 0.22);
    color: rgba(255, 255, 255, 0.35);
    cursor: not-allowed;
}
.level-cell.locked:hover  { background: rgba(0, 0, 0, 0.22); }
.level-cell.locked:active { transform: none; }
.level-cell .lock-icon { width: 18px; height: 18px; opacity: 0.55; }

/* ==========================================================================
   Animations
   ========================================================================== */

/* ==========================================================================
   Sponsor card — floating, fixed-position, never affects game layout
   ========================================================================== */

.sponsor-card {
    position: fixed;
    bottom: 12px;
    right: 12px;
    z-index: 50;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 8px 8px;
    background: linear-gradient(135deg, #ffb648, #ff7849);
    color: #1b2a4a;
    text-decoration: none;
    border-radius: 999px;
    box-shadow: 0 8px 20px rgba(255, 120, 73, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
    font-family: inherit;
    max-width: calc(100vw - 24px);
    animation: sponsorPopIn 0.5s cubic-bezier(.2, 1.4, .4, 1);
    transition: transform 0.18s ease;
}
.sponsor-card:hover  { transform: translateY(-2px); }
.sponsor-card.hidden { display: none; }

.sponsor-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #1b2a4a;
    flex-shrink: 0;
}
.sponsor-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
}
.sponsor-label {
    font-size: 9px;
    letter-spacing: 1.2px;
    opacity: 0.7;
    font-weight: 800;
}
.sponsor-msg {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sponsor-close {
    background: rgba(0, 0, 0, 0.18);
    color: #1b2a4a;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    margin-left: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.sponsor-close:hover { background: rgba(0, 0, 0, 0.3); }

@keyframes sponsorPopIn {
    0%   { transform: translateY(40px); opacity: 0; }
    100% { transform: translateY(0);    opacity: 1; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
    0%   { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1);   opacity: 1; }
}
@keyframes spin {
    0%, 100% { transform: rotate(-12deg) scale(1); }
    50%      { transform: rotate( 12deg) scale(1.15); }
}
@keyframes popUp {
    0%   { transform: translateX(-50%) translateY(-6px); opacity: 0; }
    100% { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

/* ==========================================================================
   Responsive — phones, tablets, desktops, landscape
   ========================================================================== */

@media (max-width: 360px) {
    .topbar      { padding-top: max(10px, env(safe-area-inset-top)); padding-left: 12px; padding-right: 12px; }
    .top-actions { gap: 6px; }
    .icon-btn    { width: 38px; height: 38px; }
    .icon-btn svg { width: 18px; height: 18px; }
    .level-name  { font-size: 14px; }
    .level-label { font-size: 9px; letter-spacing: 2px; }
    .bottombar   { padding-left: 14px; padding-right: 14px; gap: 10px; }
    .hint        { font-size: 10px; padding: 5px 10px; }
    .counter     { font-size: 11px; min-width: 50px; }
}

@media (max-width: 480px) {
    .level-name      { font-size: 15px; }
    .overlay-card    { padding: 26px 22px; }
    .overlay-card h2 { font-size: 22px; }
    .hint            { font-size: 11px; }
    /* Sponsor card: shrink to icon-only pill in the top-right corner so the
       bottom progress bar + counter stay fully visible on phones. */
    .sponsor-card    { top: 10px; right: 10px; bottom: auto; padding: 5px 8px 5px 5px; gap: 6px; }
    .sponsor-icon    { width: 24px; height: 24px; font-size: 12px; }
    .sponsor-text    { display: none; }
    .sponsor-close   { width: 18px; height: 18px; font-size: 12px; }
}

@media (orientation: landscape) and (max-height: 500px) {
    .topbar          { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; }
    .level-label     { font-size: 9px; }
    .level-name      { font-size: 13px; margin-top: 1px; }
    .icon-btn        { width: 36px; height: 36px; }
    .icon-btn svg    { width: 18px; height: 18px; }
    .stage           { padding: 4px 10px; }
    .bottombar       { padding-top: 6px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .hint            { display: none; }
    #board           { border-radius: 18px; }
    .overlay-card    { padding: 20px 24px; }
    .overlay-card h2 { font-size: 20px; margin-bottom: 4px; }
    .overlay-card p  { margin-bottom: 14px; }
    .confetti        { font-size: 32px; margin-bottom: 2px; }
}

@media (min-width: 600px) {
    #app          { max-width: 640px; }
    .topbar       { padding-top: max(18px, env(safe-area-inset-top)); padding-left: 22px; padding-right: 22px; }
    .level-name   { font-size: 18px; }
    .icon-btn     { width: 46px; height: 46px; }
    .icon-btn svg { width: 24px; height: 24px; }
    .bottombar    { padding-left: 26px; padding-right: 26px; }
}

@media (min-width: 1024px) {
    #app        { max-width: 680px; }
    .level-name { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .confetti { animation: none; }
}

@media (hover: none) {
    .icon-btn:hover    { background: rgba(255, 255, 255, 0.08); }
    .preview-btn:hover { background: rgba(95, 184, 107, 0.2); }
}
