/* Windows 3.1 Retro Style Sheet */
:root {
    --win-bg: #c0c0c0;         /* Classic Silver */
    --win-blue: #000080;       /* Title Bar Blue */
    --win-white: #ffffff;
    --win-gray-dark: #808080;  /* Shadow */
    --win-black: #000000;
    --desktop-bg: #008080;     /* Teal */
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 20px;
    background-color: var(--desktop-bg);
    font-family: "Microsoft Sans Serif", "Arial", sans-serif;
    font-size: 14px;
    color: var(--win-black);
    /* Pixelated pattern attempt for desktop */
    background-image: linear-gradient(45deg, #008080 25%, #000000 25%, #000000 50%, #008080 50%, #008080 75%, #000000 75%, #000000 100%);
    background-size: 4px 4px;
}

/* --- Window Frame --- */
.win-window {
    background-color: var(--win-bg);
    border-top: 2px solid var(--win-white);
    border-left: 2px solid var(--win-white);
    border-right: 2px solid var(--win-black);
    border-bottom: 2px solid var(--win-black);
    box-shadow: 4px 4px 0px rgba(0,0,0,0.5);
    max-width: 900px;
    margin: 0 auto;
    padding: 2px;
}

/* --- Title Bar --- */
.win-title-bar {
    background-color: var(--win-blue);
    color: var(--win-white);
    padding: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.win-title-icon {
    border: 1px solid var(--win-white);
    width: 20px;
    height: 20px;
    line-height: 18px;
    text-align: center;
    background: var(--win-bg);
    color: var(--win-black);
    font-family: monospace;
    font-weight: bold;
    margin-right: 8px;
    cursor: default;
}

.win-title-controls {
    display: flex;
    gap: 2px;
}

.win-btn-icon {
    width: 20px;
    height: 20px;
    background: var(--win-bg);
    border-top: 1px solid var(--win-white);
    border-left: 1px solid var(--win-white);
    border-right: 1px solid var(--win-black);
    border-bottom: 1px solid var(--win-black);
    font-size: 12px;
    line-height: 16px;
    padding: 0;
    cursor: pointer;
}
.win-btn-icon:active {
    border-top: 1px solid var(--win-black);
    border-left: 1px solid var(--win-black);
    border-right: 1px solid var(--win-white);
    border-bottom: 1px solid var(--win-white);
}

/* --- Menu Bar --- */
.win-menu-bar {
    padding: 2px 8px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--win-gray-dark);
    display: flex;
    gap: 4px;
    align-items: center;
}
.menu-item-btn {
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    padding: 2px 6px;
    margin: 0;
    cursor: pointer;
    text-align: left;
}
.menu-item-btn:hover,
.menu-item-btn:focus-visible {
    background-color: var(--win-blue);
    color: var(--win-white);
    outline: none;
}

/* --- Body Layout --- */
.win-body {
    padding: 10px;
}

.win-fieldset {
    border: 2px groove var(--win-white); /* Emulate etched border */
    border-color: var(--win-gray-dark) var(--win-white) var(--win-white) var(--win-gray-dark);
    margin-bottom: 15px;
    padding: 10px;
}

.win-fieldset legend {
    margin-left: 10px;
    padding: 0 4px;
}

.admin-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.admin-inline-form {
    margin: 8px 0 0 0;
}

.admin-image-preview-wrap {
    margin-top: 6px;
    border: 1px inset;
    background: var(--win-white);
    padding: 6px;
    display: inline-block;
    max-width: 260px;
}

.admin-image-preview {
    display: block;
    max-width: 240px;
    max-height: 240px;
    width: auto;
    height: auto;
}

.admin-checkbox-line {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.admin-link-btn {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.admin-stats-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--win-white);
}

.admin-stats-table td {
    border: 1px solid var(--win-gray-dark);
    padding: 6px 8px;
}

/* --- Form Controls --- */
.search-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.sm-group {
    width: 60px;
}

label {
    margin-bottom: 4px;
}

input[type="text"], input[type="number"], select {
    background: var(--win-white);
    border-top: 2px solid var(--win-black);
    border-left: 2px solid var(--win-black);
    border-right: 2px solid var(--win-white);
    border-bottom: 2px solid var(--win-white);
    padding: 3px;
    font-family: inherit;
    height: 24px;
}

textarea {
    background: var(--win-white);
    border-top: 2px solid var(--win-black);
    border-left: 2px solid var(--win-black);
    border-right: 2px solid var(--win-white);
    border-bottom: 2px solid var(--win-white);
    padding: 6px;
    font-family: "Courier New", monospace;
    font-size: 13px;
    resize: vertical;
    width: 100%;
    min-height: 110px;
}

/* --- Win3.1 Button --- */
.win-btn {
    background: var(--win-bg);
    border-top: 2px solid var(--win-white);
    border-left: 2px solid var(--win-white);
    border-right: 2px solid var(--win-black);
    border-bottom: 2px solid var(--win-black);
    padding: 4px 15px;
    font-weight: bold;
    cursor: pointer;
    min-width: 80px;
    text-transform: uppercase;
    font-size: 12px;
}

.win-btn:active {
    border-top: 2px solid var(--win-black);
    border-left: 2px solid var(--win-black);
    border-right: 2px solid var(--win-white);
    border-bottom: 2px solid var(--win-white);
    padding: 5px 14px 3px 16px; /* Shift text slightly */
}

/* --- Status Bar --- */
.status-bar {
    margin-top: 8px;
    padding: 2px 4px;
    border: 1px inset;
    background: var(--win-bg);
    font-style: italic;
    color: var(--win-blue);
}

/* --- Results Table --- */
.panel-results {
    margin-bottom: 15px;
}

.table-container {
    height: 250px;
    overflow-y: auto;
    background: var(--win-white);
}

.win-inset-box {
    border-top: 2px solid var(--win-black);
    border-left: 2px solid var(--win-black);
    border-right: 2px solid var(--win-white);
    border-bottom: 2px solid var(--win-white);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: var(--win-bg);
    border-bottom: 1px solid var(--win-black);
    border-right: 1px solid var(--win-gray-dark);
    padding: 4px;
    text-align: left;
    position: sticky;
    top: 0;
    font-weight: bold;
}

td {
    padding: 4px;
    border-bottom: 1px dotted #ccc;
    font-size: 13px;
}

tr:hover {
    background-color: var(--win-blue);
    color: var(--win-white);
}

tr:hover .win-btn {
    color: var(--win-black); /* Keep button text readable */
}

/* --- Player Area --- */
.player-layout {
    display: flex;
    gap: 15px;
}

.player-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cover-wrapper {
    width: 120px;
    height: 120px;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

#coverImg {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#coverPlaceholder {
    color: var(--win-white);
    font-size: 10px;
    text-align: center;
}

.track-info {
    text-align: center;
    border: 1px solid var(--win-gray-dark);
    padding: 5px;
    background: var(--win-bg);
}
.track-info h3 { margin: 0; font-size: 15px; }
.track-info p { margin: 2px 0 0; font-size: 12px; color: var(--win-blue); }

.audio-control audio {
    width: 100%;
    height: 30px;
}

.player-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

.player-btn {
    min-width: 72px;
    text-transform: none;
}

#btnLoop.is-on {
    background: var(--win-blue);
    color: var(--win-white);
}

.time-display {
    min-width: 110px;
    text-align: center;
    font-family: "Courier New", monospace;
    font-size: 12px;
    padding: 3px 6px;
    border: 1px inset;
    background: var(--win-bg);
}

/* --- Lyrics --- */
.player-right {
    flex: 2;
    display: flex;
    flex-direction: column;
}

.lyrics-header {
    margin-bottom: 4px;
    font-weight: bold;
}

.lyrics-box {
    background: var(--win-white);
    height: 200px;
    overflow-y: auto;
    padding: 10px;
}

.manual-lyrics-panel {
    margin-top: 10px;
    margin-bottom: 0;
    padding: 8px;
}

.manual-lyrics-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.manual-lyrics-controls input[type="text"] {
    flex: 1;
    min-width: 0;
}

.manual-lyrics-controls .win-btn {
    min-width: 86px;
    text-transform: none;
}

.lyrics-candidate-box {
    margin-top: 8px;
    max-height: 165px;
    overflow-y: auto;
    background: var(--win-white);
}

#lyricsCandidatesTable td {
    font-size: 12px;
}

.lyrics-content {
    margin: 0;
    font-family: "Courier New", monospace;
    font-size: 13px;
    white-space: pre-wrap;
    line-height: 1.7;
}

.lyric-line {
    --line-shift: 0px;
    --line-scale: 1;
    --line-opacity: 1;
    --line-blur: 0px;
    --line-duration: 380ms;
    --line-delay: 0ms;
    padding: 2px 4px;
    color: #333;
    transform: translate3d(0, var(--line-shift), 0) scale(var(--line-scale));
    opacity: var(--line-opacity);
    filter: blur(var(--line-blur));
    transform-origin: center center;
    transition:
        transform var(--line-duration) cubic-bezier(0.2, 0.75, 0.2, 1) var(--line-delay),
        opacity var(--line-duration) ease var(--line-delay),
        filter var(--line-duration) ease var(--line-delay),
        background-color 0.24s ease,
        color 0.24s ease;
    will-change: transform, opacity, filter;
}

.lyric-line.active {
    --line-shift: 0px;
    --line-scale: 1;
    --line-opacity: 1;
    --line-blur: 0px;
    background: var(--win-blue);
    color: var(--win-white);
    font-weight: bold;
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
}

.lyric-spacer {
    width: 100%;
    pointer-events: none;
}

.lyric-plain {
    white-space: pre-wrap;
}

.result-row.active {
    background: var(--win-blue);
    color: var(--win-white);
}

.result-row.active .win-btn {
    color: var(--win-black);
}

.dialog-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}

.dialog-mask[hidden] {
    display: none !important;
}

.dialog-window {
    width: min(560px, 100%);
    background-color: var(--win-bg);
    border-top: 2px solid var(--win-white);
    border-left: 2px solid var(--win-white);
    border-right: 2px solid var(--win-black);
    border-bottom: 2px solid var(--win-black);
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
}

.dialog-title-bar {
    margin-bottom: 0;
}

.dialog-body {
    padding: 10px;
    max-height: min(65vh, 440px);
    overflow: auto;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 10px 10px 10px;
}

.about-lines {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.5;
    font-family: "Courier New", monospace;
}

.recent-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.recent-list th,
.recent-list td {
    border: 1px solid var(--win-gray-dark);
    padding: 5px 6px;
    text-align: left;
    vertical-align: top;
}

.recent-list th {
    background: #d8d8d8;
}

.recent-empty {
    padding: 12px;
}

.download-meta {
    margin-bottom: 8px;
    line-height: 1.5;
}

.download-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.download-list th,
.download-list td {
    border: 1px solid var(--win-gray-dark);
    padding: 5px 6px;
    text-align: left;
    vertical-align: middle;
}

.download-list th {
    background: #d8d8d8;
}

.download-action-btn {
    min-width: 58px;
    text-transform: none;
    padding: 3px 8px;
}

.download-progress-wrap {
    margin-top: 10px;
    padding: 8px;
    border: 1px inset;
    background: var(--win-white);
}

.download-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
}

.download-progress-label {
    color: #111;
    font-weight: bold;
}

.download-progress-percent {
    font-family: "Courier New", monospace;
    color: var(--win-blue);
    min-width: 40px;
    text-align: right;
}

.download-progress-track {
    margin-top: 6px;
    height: 14px;
    border: 1px solid var(--win-gray-dark);
    background: #ececec;
    overflow: hidden;
    position: relative;
}

.download-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--win-blue);
    transition: width 0.12s linear;
}

.download-progress-bar.is-indeterminate {
    animation: download-indeterminate 1.05s linear infinite;
}

.download-progress-bar.is-error {
    background: #8d0a0a;
    animation: none;
}

.download-progress-bar.is-done {
    background: #0a6a0a;
    animation: none;
}

.download-progress-meta {
    margin-top: 5px;
    font-family: "Courier New", monospace;
    font-size: 12px;
    color: #222;
}

@keyframes download-indeterminate {
    0% {
        transform: translateX(-140%);
    }
    100% {
        transform: translateX(320%);
    }
}

.notice-text-block {
    margin: 6px 0 10px 0;
    padding: 8px;
    border: 1px inset;
    background: var(--win-white);
    line-height: 1.55;
    white-space: normal;
}

.notice-image-wrap {
    margin: 0 0 10px 0;
    border: 1px inset;
    background: var(--win-white);
    padding: 8px;
    text-align: center;
}

.notice-image {
    max-width: 100%;
    max-height: 320px;
    width: auto;
    height: auto;
}

.comment-fieldset {
    margin-bottom: 0;
}

.comment-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.comment-list {
    margin-top: 8px;
    border: 1px inset;
    background: var(--win-white);
    max-height: 240px;
    overflow-y: auto;
    padding: 6px;
}

.comment-item {
    padding: 6px 4px 8px 4px;
    border-bottom: 1px dotted #808080;
}

.comment-item:last-child {
    border-bottom: none;
}

.comment-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    margin-bottom: 4px;
}

.comment-user {
    font-weight: bold;
}

.comment-time {
    color: #333;
    white-space: nowrap;
}

.comment-content {
    line-height: 1.5;
    word-break: break-word;
    white-space: normal;
}

.comment-pager {
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.comment-page-indicator {
    font-family: "Courier New", monospace;
    font-size: 12px;
    white-space: nowrap;
}

.win-footer {
    font-family: monospace;
    padding-top: 4px;
    border-top: 1px solid var(--win-gray-dark);
    font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
    .lyric-line {
        transition: background-color 0.16s ease, color 0.16s ease;
    }
}

/* --- Responsive Mobile --- */
@media (max-width: 600px) {
    body { padding: 0; }
    .win-window { width: 100%; height: 100vh; overflow-y: auto; box-shadow: none; }
    
    .search-grid {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .form-group, .sm-group { width: 100%; }
    
    .player-layout {
        flex-direction: column;
    }
    
    .lyrics-box {
        height: 150px;
    }

    .manual-lyrics-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .win-title-bar {
        position: sticky;
        top: 0;
        z-index: 10;
    }
}
