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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: Arial, Helvetica, sans-serif;
    background: #1a1a2e;
    color: #fff;
    -webkit-user-select: none;
    user-select: none;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    height: 100%;
    padding: 15px;
    text-align: center;
}

.footer-legend {
    margin-top: auto;
    font-size: 0.8em;
    color: #777;
    padding: 10px 0 5px;
}

.screen.active { display: flex; }

h1 {
    font-size: 1.5em;
    margin-bottom: 12px;
    color: #aec90b;
    flex-shrink: 0;
}

.subtitle {
    font-size: 0.9em;
    color: #ccc;
    margin-bottom: 10px;
}

.error-msg {
    color: #e74c3c;
    font-size: 0.85em;
    min-height: 1.2em;
}

input[type="text"], input[type="password"] {
    width: 100%;
    max-width: 280px;
    padding: 12px;
    margin: 6px 0;
    border: 1px solid #444;
    border-radius: 8px;
    background: #16213e;
    color: #fff;
    font-size: 1em;
    outline: none;
    flex-shrink: 0;
}

input[type="text"]:focus, input[type="password"]:focus { border-color: #aec90b; }

button {
    padding: 12px 30px;
    margin: 6px 0;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    width: 100%;
    max-width: 280px;
    flex-shrink: 0;
}

button:disabled { opacity: 0.5; }

.btn-primary { background: #aec90b; color: #1a1a2e; font-weight: bold; }
.btn-secondary { background: #444; color: #fff; }

.btn-back {
    background: transparent;
    color: #aec90b;
    border: 1px solid #aec90b;
    max-width: 200px;
}

.admin-link {
    margin-top: 25px;
    color: #888;
    font-size: 0.85em;
    cursor: pointer;
    text-decoration: underline;
    flex-shrink: 0;
}

#admin-login-form {
    display: none;
    margin-top: 8px;
    width: 100%;
    max-width: 280px;
}

.puzzle-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    width: 100%;
    min-height: 0;
}

canvas {
    touch-action: none;
    max-width: 100%;
    max-height: 65vh;
}

.game-thumbnail {
    position: fixed;
    bottom: 10px;
    left: 10px;
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #aec90b;
    z-index: 10;
    display: block;
    cursor: pointer;
}
.game-thumbnail.enlarged {
    width: 80vw;
    height: 80vh;
    max-width: 600px;
    max-height: 500px;
    z-index: 1000;
    border-radius: 12px;
    bottom: 50%;
    left: 50%;
    transform: translate(-50%, 50%);
}
.thumb-toggle {
    position: fixed;
    bottom: 95px;
    left: 18px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid #aec90b;
    background: #16213e;
    color: #aec90b;
    font-size: 1.1em;
    cursor: pointer;
    z-index: 11;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.thumb-toggle.visible { display: flex; }
.thumb-toggle.enlarged-toggle {
    bottom: calc(50% - 250px + 10px);
    left: calc(50% - 300px + 10px);
    z-index: 1001;
    bottom: calc(50vh - 250px + 18px);
    left: calc(50vw - 300px + 18px);
    max-left: calc(50vw - 300px + 18px);
}

.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 500px;
    padding: 8px 12px;
    background: #16213e;
    border-radius: 8px;
    margin-bottom: 8px;
    flex-shrink: 0;
    font-size: 0.95em;
}

#game-image-name {
    font-size: 1.2em;
    font-weight: bold;
    color: #aec90b;
}

#game-player-name {
    color: #ccc;
}

.timer {
    font-size: 1.1em;
    font-weight: bold;
    color: #58a7d3;
    font-variant-numeric: tabular-nums;
}

#image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
    width: 100%;
    max-width: 600px;
    min-height: 0;
}

.image-card {
    width: calc(50% - 5px);
    max-width: 170px;
    background: #16213e;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
}

.image-card:active { border-color: #aec90b; }

.image-card img {
    width: 100%;
    height: auto;
    display: block;
}

.image-card .image-card-name {
    padding: 8px;
    font-size: 0.9em;
    color: #ddd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.records-summary {
    font-size: 0.9em;
    color: #58a7d3;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.admin-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.tab-btn {
    padding: 8px 20px;
    background: #16213e;
    color: #888;
    border: 1px solid #333;
    border-radius: 6px;
    font-size: 0.9em;
    max-width: none;
    width: auto;
}

.tab-btn.active {
    background: #aec90b;
    color: #1a1a2e;
    border-color: #aec90b;
}

.admin-tab-content {
    flex: 1;
    width: 100%;
    max-width: 500px;
    overflow-y: auto;
    overflow-x: auto;
    min-height: 0;
}

.admin-tab-content #users-list {
    overflow-x: auto;
}

#users-list .records-table {
    width: 100%;
}

#users-list .records-table th:first-child,
#users-list .records-table td:first-child {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    text-align: center;
}

#users-list .records-table th:last-child,
#users-list .records-table td:last-child {
    width: 55px;
    min-width: 55px;
}

.admin-list {
    width: 100%;
    padding: 5px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.admin-image-item {
    width: calc(50% - 6px);
    max-width: 180px;
    background: #16213e;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
}

.op-card-mobile {
    width: calc(50% - 6px);
    min-width: 130px;
    max-width: 180px;
}
.op-card-mobile .op-photo-wrap {
    height: 120px;
}
.op-card-mobile .op-photo-wrap img {
    height: 120px;
}

.admin-image-item:active { border-color: #aec90b; }

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

.admin-image-name {
    padding: 8px;
    font-size: 0.85em;
    color: #ddd;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.op-photo-wrap {
    position: relative;
    width: 100%;
    height: 150px;
}
.op-photo-wrap img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    display: block;
}
.op-overlay-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: none;
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    font-size: 1.3em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.op-overlay-btn:hover { background: rgba(0,0,0,0.85); }

.admin-image-options {
    padding: 6px 8px 10px;
    text-align: center;
}

.admin-image-options .edit-btn {
    width: auto;
    padding: 5px 12px;
    background: #58a7d3;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.8em;
    margin: 2px;
}

.admin-image-options .del-btn {
    width: auto;
    padding: 5px 12px;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.8em;
    margin: 2px;
}

.approve-btn {
    padding: 8px 18px;
    background: #27ae60;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    cursor: pointer;
    margin: 3px 0;
    width: auto;
}

.reject-btn {
    padding: 8px 18px;
    background: #e67e22;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    cursor: pointer;
    margin: 3px 0;
    width: auto;
}

.approved-badge {
    padding: 8px 18px;
    background: #27ae60;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    cursor: pointer;
    margin: 3px 0;
    width: auto;
}

.auto-approved-badge {
    padding: 8px 18px;
    background: #fdf3cd;
    color: #856404;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    cursor: pointer;
    margin: 3px 0;
    width: auto;
}

.pending-badge {
    padding: 8px 18px;
    background: #e67e22;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95em;
    cursor: pointer;
    margin: 3px 0;
    width: auto;
}

.admin-add {
    width: 100%;
    padding: 10px 0;
    flex-shrink: 0;
}

#camera-input { display: none; }

.records-list {
    width: 100%;
    overflow-y: auto;
    flex: 1;
}

.records-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
    overflow: visible;
}

.records-table th {
    background: #16213e;
    color: #aec90b;
    padding: 8px 6px;
    text-align: left;
    border-bottom: 1px solid #333;
}

.records-table td {
    padding: 8px 6px;
    border-bottom: 1px solid #222;
    vertical-align: middle;
}

.records-table .edit-btn {
    padding: 6px 12px;
    background: #58a7d3;
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    width: auto;
    margin: 2px;
}

.records-table .del-btn {
    padding: 6px 12px;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    width: auto;
    margin: 2px;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-box {
    background: #2a2a3e;
    border: 1px solid #555;
    border-radius: 10px;
    padding: 25px 35px;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

#modal-message {
    font-size: 1.05em;
    margin-bottom: 18px;
    line-height: 1.4;
}

.modal-ok-btn, .modal-confirm-btn, .modal-cancel-btn {
    padding: 8px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    margin: 6px 12px;
}

.modal-ok-btn { background: #58a7d3; color: #fff; }
.modal-confirm-btn { background: #e74c3c; color: #fff; }
.modal-cancel-btn { background: #555; color: #fff; }

.date-btn {
    background: none;
    border: 1px solid #555;
    color: #ddd;
    border-radius: 5px;
    padding: 8px 16px;
    font-size: 1em;
    cursor: pointer;
    width: auto;
    font-family: monospace;
    letter-spacing: 1px;
}

.date-btn:hover { background: #333; }

.del-x-btn {
    background: none;
    border: none;
    color: #e74c3c;
    font-size: 1.2em;
    cursor: pointer;
    padding: 2px 6px;
}

.del-x-btn:hover { color: #ff6b6b; }

.user-actions { display: flex; flex-direction: column; gap: 4px; position: absolute; right: 0; top: 100%; z-index: 10; background: #16213e; border: 1px solid #444; border-radius: 6px; padding: 6px; white-space: nowrap; min-width: 160px; }

.user-actions .edit-btn,
.user-actions .cancel-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 5px;
    font-size: 1.2em;
    cursor: pointer;
    width: auto;
    white-space: nowrap;
    font-family: monospace;
}

.user-actions .edit-btn { background: #58a7d3; color: #fff; }
.user-actions .cancel-btn { background: #555; color: #fff; }
.user-actions .delete-btn-menu { background: #e74c3c; color: #fff; }
.user-actions .close-menu-btn { background: #555; color: #fff; }
.user-actions .menu-date { color: #888; font-size: 0.8em; padding: 2px 4px; text-align: center; }
.user-actions hr { border: none; border-top: 1px solid #444; margin: 2px 0; }

.nro-input {
    width: 40px;
    padding: 0px;
    background: #1a1a2e;
    color: #ddd;
    border: 0px solid #444;
    border-radius: 0px;
    text-align: center;
    font-size: 16px;
    font-family: monospace;
}
.nro-input:focus { outline: none; }

.nro-filter-input {
    width: 44px;
    padding: 4px 2px;
    background: #0d1117;
    color: #aec90b;
    border: 1px solid #444;
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
    font-family: monospace;
}

.name-filter-input {
    width: 100%;
    padding: 6px 8px;
    background: #0d1117;
    color: #ccc;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 14px;
    max-width: none;
}

.nro-filter-input:focus, .name-filter-input:focus { border-color: #aec90b; outline: none; }

#connected-toggle-btn {
    background: #0d1117;
    color: #aec90b;
    border: 1px solid #aec90b;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}
#connected-toggle-btn:hover { background: #aec90b; color: #0d1117; }
.machining-op-btn {
    display: inline-block;
    margin: 4px;
    padding: 8px 14px;
    background: #34495e;
    color: #fff;
    border: 1px solid #555;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
}
.machining-op-btn:hover { background: #e67e22; }

.user-photo-card { position: relative; }

.lightbox-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: pointer;
}
.lightbox-overlay img {
    max-width: 95vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}

.preview-btn {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.7em;
    cursor: pointer;
    z-index: 2;
}

.user-photos-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
}
.user-photos-container .admin-image-item {
    width: auto;
}

.photo-bar {
    display: flex;
    gap: 3px;
}
.photo-bar-seg {
    display: inline-block;
    width: 7px;
    height: 15px;
    border-radius: 4px;
    background: #fff;
    border: 0px solid #888;
}
.photo-bar-seg.filled {
    background: #27ae60;
    border-color: #27ae60;
}

.select-header {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 12px;
}
.select-header > div:first-child {
    text-align: center;
}
.select-icons {
    display: flex;
    flex-direction: row;
    gap: 64px;
    margin-top: 8px;
    flex-shrink: 0;
    justify-content: center;
}
.icon-btn {
    background: #333;
    color: #fff;
    border: 2px solid #555;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    font-size: 1.3em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.icon-btn:hover {
    border-color: #aec90b;
    background: #444;
}

.top-players-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    cursor: pointer;
}
.top-players-box {
    background: #16213e;
    border: 2px solid #aec90b;
    border-radius: 12px;
    padding: 20px 30px;
    min-width: 260px;
    cursor: default;
}
.top-players-box h2 {
    margin: 0 0 12px;
    color: #aec90b;
    text-align: center;
}
.top-player-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #333;
}
.top-player-row:last-child { border-bottom: none; }
.top-player-rank {
    font-size: 1.4em;
    width: 36px;
    text-align: center;
}
.top-player-name { flex: 1; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.top-player-score { color: #aec90b; font-weight: bold; white-space: nowrap; margin-left: 8px; }

.records-table .best-row td {
    color: #aec90b;
    font-weight: bold;
}

.grid-status {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 4px 8px 8px;
}

.grid-dot {
    display: inline-block;
    width: 28px;
    height: 28px;
    line-height: 28px;
    border-radius: 50%;
    font-size: 0.7em;
    font-weight: bold;
    text-align: center;
}

.grid-dot.avail {
    background: #aec90b;
    color: #1a1a2e;
}

.grid-dot.done {
    background: #2a6b2a;
    color: #8f8;
    font-size: 0.85em;
}

.image-card.done-puzzle {
    opacity: 0.5;
}

.admin-bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding-top: 10px;
}
.admin-settings-wrapper {
    position: relative;
}
.admin-settings-btn {
    background: none;
    border: none;
    font-size: 1.8em;
    color: #aec90b;
    cursor: pointer;
    padding: 4px 8px;
}
.admin-settings-btn:hover { color: #fff; }
.admin-settings-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: #16213e;
    border: 1px solid #58a7d3;
    border-radius: 8px;
    padding: 6px 0;
    min-width: 170px;
    z-index: 100;
}
.admin-settings-menu button {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: #ccc;
    padding: 8px 16px;
    text-align: left;
    cursor: pointer;
    font-size: 0.9em;
    white-space: nowrap;
}
.admin-settings-menu button:hover { background: #1a1a2e; color: #aec90b; }
.admin-exit-btn {
    font-size: 1.4em;
    padding: 4px 10px;
}

.admin-photo-delete-x {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    background: #e74c3c;
    color: #fff;
    border-radius: 50%;
    font-size: 1.2em;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    z-index: 3;
}

.game-bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 6px 0;
    flex-shrink: 0;
}
.game-bottom-left, .game-bottom-right {
    display: flex;
    gap: 8px;
}
.back-btn {
    background: #16213e;
    color: #aec90b;
    border: 2px solid #aec90b;
    border-radius: 10px;
    width: 56px;
    height: 42px;
    font-size: 1.6em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.back-btn:hover {
    background: #aec90b;
    color: #16213e;
}
