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

:root {
    --dy-orange: #fe8e14;
    --dy-gray: #999999;
    --dy-black-2b: #2b2b2b;
    --dy-black-34: #343434;
    --white: #ffffff;
    --overlay: rgba(0, 0, 0, 0.55);
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--dy-black-2b);
    color: var(--white);
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    touch-action: manipulation;
}

.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--dy-black-2b);
}

.hidden {
    display: none !important;
}

.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e1e1e;
    z-index: 120;
}

#license-screen {
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 10% 10%, #4a4a4a 0%, #2b2b2b 45%, #1e1e1e 100%);
}

.license-wrap {
    width: min(560px, 92vw);
    background: #343434;
    border: 1px solid #4a4a4a;
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.4);
}

.license-wrap h1 {
    font-size: 26px;
    margin-bottom: 8px;
}

.license-subtitle {
    color: #d0d0d0;
    font-size: 14px;
    margin-bottom: 16px;
}

.license-label {
    display: block;
    font-size: 13px;
    color: #d8d8d8;
    margin-bottom: 6px;
}

.license-input {
    width: 100%;
    height: 44px;
    border: 1px solid #5a5a5a;
    background: #252525;
    color: #ffffff;
    border-radius: 8px;
    padding: 0 10px;
    margin-bottom: 12px;
}

.license-input:focus {
    outline: 2px solid rgba(254, 142, 20, 0.35);
    border-color: var(--dy-orange);
}

.license-btn {
    border: 0;
    border-radius: 8px;
    height: 42px;
    min-width: 150px;
    background: var(--dy-orange);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.init-content {
    text-align: center;
    padding: 24px;
}

.spinner {
    width: 44px;
    height: 44px;
    margin: 0 auto 16px;
    border: 4px solid #555;
    border-top-color: var(--dy-orange);
    border-radius: 999px;
    animation: spin 1s linear infinite;
}

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

#init-status {
    margin-top: 8px;
    color: var(--dy-gray);
    font-size: 14px;
}

#camera-container {
    position: relative;
    flex: 1;
    background: black;
    overflow: hidden;
}

#camera-view,
#camera-video,
#camera-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#camera-video {
    object-fit: cover;
}

#camera-overlay {
    pointer-events: none;
}

.icon-button {
    border: none;
    color: white;
    background: rgba(52, 52, 52, 0.75);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 22px;
    cursor: pointer;
}

.top-right {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 20;
}

.auto-indicator {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--overlay);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    z-index: 20;
}

.thumbnail-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 106px;
    height: 80px;
    display: flex;
    gap: 8px;
    padding: 8px;
    overflow-x: auto;
    z-index: 15;
}

.thumbnail-item {
    position: relative;
    width: 64px;
    min-width: 64px;
    height: 72px;
    border: 0;
    background: #3f3f3f;
    cursor: pointer;
}

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

.thumbnail-remove {
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 20px;
    border: 0;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 14px;
    line-height: 20px;
    cursor: pointer;
}

.bottom-controls {
    height: 100px;
    display: grid;
    grid-template-columns: 1fr 72px 1fr;
    align-items: center;
    padding: 16px 24px;
    background: var(--overlay);
}

.ghost-icon {
    justify-self: start;
    width: 48px;
    height: 48px;
    border: 0;
    color: #fff;
    font-size: 30px;
    background: transparent;
    cursor: pointer;
}

#next-btn {
    justify-self: end;
}

.capture-button {
    width: 72px;
    height: 72px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.25);
    cursor: pointer;
    padding: 7px;
}

.capture-inner {
    display: block;
    width: 58px;
    height: 58px;
    border-radius: 999px;
    background: #fff;
}

.capture-button.capturing .capture-inner {
    background: var(--dy-orange);
}

.disabled {
    opacity: 0.3;
    pointer-events: none;
}

.top-action-bar {
    height: 56px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    background: var(--dy-black-34);
    align-items: center;
}

.icon-text-btn {
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 10px 4px;
    cursor: pointer;
}

.page-indicator {
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dy-gray);
    font-size: 14px;
}

.result-view {
    flex: 1;
    display: grid;
    grid-template-columns: 38px 1fr 38px;
    align-items: center;
    padding: 6px 6px;
    gap: 6px;
    min-height: 0;
    overflow: hidden;
}

#result-canvas {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    align-self: stretch;
    background: #161616;
}

.pager-btn {
    border: 0;
    background: #3c3c3c;
    color: white;
    width: 32px;
    height: 72px;
    border-radius: 6px;
    font-size: 28px;
    cursor: pointer;
}

.filter-bar {
    height: 56px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--dy-black-34);
}

.filter-btn {
    border: 0;
    background: transparent;
    color: var(--dy-gray);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.filter-btn.active {
    color: var(--dy-orange);
}

.settings-modal {
    width: min(520px, 92vw);
    background: var(--dy-black-34);
    border-radius: 12px;
    overflow: hidden;
}

.settings-header {
    height: 56px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #4c4c4c;
}

.close-btn {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
}

.settings-body {
    padding: 14px 16px;
    display: grid;
    gap: 14px;
}

.setting-item {
    display: grid;
    gap: 8px;
}

.setting-item label {
    font-size: 14px;
    color: #e2e2e2;
}

.setting-item span {
    color: var(--dy-orange);
    margin-left: 6px;
    font-family: Consolas, monospace;
}

input[type="range"] {
    width: 100%;
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background: #6a6a6a;
    transition: 0.2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: white;
    transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #6ac4bb;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.toggle-label {
    font-size: 13px;
    color: #d2d2d2;
}

.settings-footer {
    padding: 12px 16px;
    border-top: 1px solid #4c4c4c;
}

.action-btn {
    border: 0;
    border-radius: 8px;
    height: 42px;
    min-width: 120px;
    padding: 0 16px;
    font-weight: 700;
    cursor: pointer;
}

.action-btn.primary {
    background: var(--dy-orange);
    color: #fff;
}

.save-menu {
    position: fixed;
    min-width: 180px;
    background: #2a2a2a;
    border: 1px solid #545454;
    border-radius: 10px;
    padding: 6px;
    z-index: 130;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}

.save-menu-item {
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: #fff;
    height: 36px;
    border-radius: 6px;
    padding: 0 10px;
    cursor: pointer;
}

.save-menu-item:hover {
    background: #3e3e3e;
}

.toast {
    position: fixed;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
    background: #1e1e1e;
    color: #fff;
    border: 1px solid #4b4b4b;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    transition: 0.25s ease;
    z-index: 140;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

button {
    touch-action: manipulation;
}

/* Sort overlay */
.sort-modal {
    width: min(520px, 92vw);
    max-height: 90vh;
    background: var(--dy-black-34);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sort-header {
    height: 56px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #4c4c4c;
}

.sort-header h2 {
    font-size: 18px;
}

.sort-done-btn {
    border: 0;
    background: transparent;
    color: var(--dy-orange);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.sort-hint {
    text-align: center;
    color: var(--dy-gray);
    font-size: 14px;
    padding: 8px 0;
}

.sort-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
}

.sort-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    margin: 4px 0;
    background: var(--dy-black-2b);
    border-radius: 8px;
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
    transition: opacity 0.15s;
}

.sort-item.dragging {
    opacity: 0.4;
}

.sort-item.drag-over {
    border-top: 2px solid var(--dy-orange);
}

.sort-item img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
}

.sort-label {
    flex: 1;
    font-size: 14px;
}

.sort-handle {
    font-size: 20px;
    color: var(--dy-gray);
    cursor: grab;
    padding: 0 4px;
    -webkit-user-select: none;
    user-select: none;
}

/* Edit screen */
.edit-header {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dy-black-34);
    font-size: 18px;
    font-weight: 700;
}

.edit-container {
    flex: 1;
    position: relative;
    background: #161616;
    overflow: hidden;
}

#edit-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.edit-footer {
    height: 56px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--dy-black-34);
}

.edit-footer-btn {
    border: 0;
    background: transparent;
    color: var(--dy-gray);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.edit-footer-btn.primary {
    color: var(--dy-orange);
}

/* Override Dynamsoft license message styling */
.dls-license-msg-content {
    color: #222 !important;
    background: #fff !important;
}

.dls-license-msg-content a {
    color: #0070f3 !important;
}

@media (max-width: 620px) {
    .top-action-bar {
        grid-template-columns: repeat(3, 1fr);
        height: auto;
        row-gap: 2px;
        padding: 4px 0;
    }

    .icon-text-btn {
        height: 34px;
    }
}
