* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #eee;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 600px;
    margin: 0 auto;
    padding: 1rem;
    width: 100%;
}

header {
    text-align: center;
    padding: 1rem 0;
    position: relative;
}

header .logo {
    height: 78px;
    width: auto;
}

#logo-link {
    text-decoration: none;
}

/* Language Switcher */
.lang-switcher {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: #16213e;
    color: #aaa;
    border: 1px solid #333;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    outline: none;
}

.lang-switcher:hover,
.lang-switcher:focus {
    border-color: #e94560;
    color: #eee;
}

.lang-switcher option {
    background: #16213e;
    color: #eee;
}

/* Hamburger Menu */
.hamburger {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 24px;
    height: 18px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background: #aaa;
    border-radius: 1px;
    transition: all 0.3s;
}

.hamburger:hover span {
    background: #e94560;
}

.hamburger.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger.active span:nth-child(2) {
    opacity: 0;
}

.hamburger.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

.nav-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: #16213e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 0.5rem 0;
    min-width: 140px;
    display: none;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.nav-menu.active {
    display: block;
}

.nav-menu a {
    display: block;
    padding: 0.6rem 1rem;
    color: #eee;
    text-decoration: none;
    transition: background 0.2s;
}

.nav-menu a:hover {
    background: #1a1a2e;
    color: #e94560;
}

/* Static Pages (About, Imprint) */
.static-page {
    width: 100%;
    max-width: 500px;
    text-align: center;
    padding: 1rem;
}

.static-page h2 {
    color: #e94560;
    margin-bottom: 1.5rem;
}

.static-content {
    text-align: left;
    color: #ccc;
    line-height: 1.7;
    margin-bottom: 2rem;
}

.static-content p {
    margin-bottom: 1rem;
}

.static-content strong {
    color: #eee;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal {
    background: #16213e;
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 320px;
    width: 100%;
    border: 1px solid #333;
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-message {
    color: #eee;
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 1.5rem;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.modal-actions button {
    flex: 1;
    padding: 0.7rem 1rem;
}

/* Solver Modal */
.solver-modal {
    text-align: center;
}

.solver-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #333;
    border-top-color: #00d4ff;
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.solver-modal .modal-message {
    margin-bottom: 1rem;
}

.solver-modal button {
    min-width: 120px;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 2rem;
}

/* Buttons */
button {
    border: none;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: #e94560;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #ff6b6b;
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-secondary {
    background: #16213e;
    color: #eee;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover:not(:disabled) {
    background: #1a1a2e;
}

.btn-explore {
    background: linear-gradient(135deg, #00d4ff, #0099cc);
    color: #000;
    font-weight: bold;
    border: none;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.4);
}

.btn-explore:hover:not(:disabled) {
    background: linear-gradient(135deg, #00e5ff, #00b3e6);
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.6);
}

/* Home Screen */
.home-screen {
    text-align: center;
    width: 100%;
}

.tagline {
    margin-bottom: 2rem;
    font-size: 1.1rem;
    color: #aaa;
}

/* Public Puzzles Gallery */
.public-gallery {
    margin-top: 2.5rem;
    width: 100%;
}

.gallery-title {
    color: #888;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.75rem;
    justify-items: center;
}

.gallery-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.gallery-item:hover {
    border-color: #e94560;
    transform: scale(1.05);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-size {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 3px;
}

/* Creator Screen */
.creator-screen {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.step-select {
    padding: 2rem;
    text-align: center;
}

.creator-instruction {
    color: #ccc;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.terms-link {
    display: block;
    margin-bottom: 1.5rem;
    font-size: 0.8rem;
    color: #666;
    text-decoration: none;
}

.terms-link:hover {
    color: #e94560;
    text-decoration: underline;
}

.canvas-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#puzzle-canvas {
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: block;
    margin: 0 auto;
}

/* Grid Options */
.grid-options {
    width: 100%;
    text-align: center;
}

.grid-options .label {
    margin-bottom: 0.75rem;
    color: #aaa;
}

.grid-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.btn-grid {
    background: #16213e;
    color: #eee;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    border: 2px solid transparent;
}

.btn-grid:hover {
    background: #1f2b47;
}

.btn-grid.active {
    border-color: #e94560;
    background: #2a1f3d;
}

/* Visibility Option */
.visibility-option {
    width: 100%;
    text-align: center;
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: #aaa;
    font-size: 0.9rem;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #e94560;
    cursor: pointer;
}

/* Creator Actions */
.creator-actions {
    width: 100%;
    text-align: center;
    margin-top: 0.5rem;
}

/* Share Screen */
.share-screen {
    width: 100%;
    text-align: center;
    padding: 1rem;
}

.share-screen h2 {
    color: #4ade80;
    margin-bottom: 1rem;
}

.share-instructions {
    color: #aaa;
    margin-bottom: 1rem;
}

.share-link-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.share-link-container input {
    flex: 1;
    padding: 0.8rem;
    border: 1px solid #333;
    border-radius: 8px;
    background: #16213e;
    color: #eee;
    font-size: 0.9rem;
}

.feedback {
    color: #4ade80;
    height: 1.5rem;
    margin-bottom: 0.5rem;
}

.expiration-info {
    color: #888;
    font-size: 0.85rem;
    font-style: italic;
}

.share-screen .expiration-info {
    margin-bottom: 1rem;
}

.pending-info {
    color: #fbbf24;
    font-size: 0.85rem;
    font-style: italic;
    margin-bottom: 0.5rem;
}

.share-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

/* Player Screen */
.player-screen {
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 1rem;
    gap: 1rem;
}

.puzzle-stats {
    font-size: 1.1rem;
    color: #aaa;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 400px;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    background: transparent;
    color: #aaa;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
}

.btn-small:hover {
    color: #fff;
    border-color: #666;
}

.puzzle-hint {
    font-size: 0.85rem;
    color: #666;
    margin: 0;
}

#player-canvas {
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    touch-action: manipulation;
}

.player-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    justify-content: center;
}

.player-actions button {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
}

/* Active state for secondary buttons (e.g., Numbers toggle) */
.btn-secondary.active {
    background: #2a1f3d;
    border-color: #4ade80;
    color: #4ade80;
}

/* Tips Overlay */
.tips-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.tips-overlay.hidden {
    display: none;
}

.tips-content {
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 340px;
    width: 90%;
    position: relative;
}

.tips-content h3 {
    margin: 0 0 1rem 0;
    color: #fff;
    font-size: 1.2rem;
}

.tips-content ul {
    margin: 0;
    padding-left: 1.2rem;
    color: #ccc;
    line-height: 1.6;
}

.tips-content li {
    margin-bottom: 0.5rem;
}

.tips-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: none;
    color: #888;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.tips-close:hover {
    color: #fff;
}

/* Win Screen */
.win-screen {
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.win-screen h2 {
    color: #4ade80;
    font-size: 1.8rem;
}

#win-canvas {
    border-radius: 8px;
    box-shadow: 0 4px 30px rgba(74, 222, 128, 0.3);
    cursor: pointer;
}

#win-canvas:hover {
    box-shadow: 0 4px 40px rgba(74, 222, 128, 0.5);
}

.win-hint {
    font-size: 0.85rem;
    color: #666;
}

.win-stats {
    color: #aaa;
    font-size: 1.1rem;
}

.win-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

/* Admin Page */
.admin-page {
    width: 100%;
    text-align: center;
    padding: 1rem;
}

.admin-page h2 {
    color: #e94560;
    margin-bottom: 1rem;
}

.admin-section {
    margin-bottom: 2rem;
    text-align: left;
}

.admin-section h3 {
    color: #888;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #333;
    padding-bottom: 0.5rem;
}

.admin-puzzles {
    margin: 0.5rem 0;
}

.admin-empty {
    color: #666;
    font-style: italic;
    font-size: 0.9rem;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.admin-item {
    background: #16213e;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #333;
    position: relative;
    transition: all 0.3s;
}

.admin-item-success {
    border-color: #4ade80;
    box-shadow: 0 0 10px rgba(74, 222, 128, 0.3);
}

.admin-item-deleted {
    opacity: 0;
    transform: scale(0.8);
}

.admin-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
}

.btn-delete-corner {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(233, 69, 96, 0.9);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-delete-corner:hover {
    opacity: 1;
}

.admin-item-info {
    padding: 0.5rem;
    font-size: 0.75rem;
    color: #888;
    display: flex;
    justify-content: space-between;
}

.admin-item-info .expiry {
    color: #f59e0b;
}

.admin-item-info .expiry.extended {
    color: #4ade80;
}

.admin-item-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
}

.btn-approve, .btn-extend {
    flex: 1;
    padding: 0.4rem;
    font-size: 0.8rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.btn-approve {
    background: #4ade80;
    color: #000;
}

.btn-approve:hover {
    background: #22c55e;
}

.btn-extend {
    background: #3b82f6;
    color: #fff;
}

.btn-extend:hover {
    background: #2563eb;
}

/* Error Screen */
.error-screen {
    text-align: center;
}

.error-screen h2 {
    color: #e94560;
    margin-bottom: 1rem;
}

.error-screen p {
    color: #aaa;
    margin-bottom: 2rem;
}

.error-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

/* Responsive */
@media (max-width: 400px) {
    #app {
        padding: 0.5rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .grid-buttons {
        gap: 0.3rem;
    }

    .btn-grid {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
    }
}
