* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: Arial, sans-serif;
    background: #7a7a7a;
    color: #ffffff;
}

button,
input,
select,
textarea {
    font: inherit;
}

.layout {
    display: grid;
    grid-template-columns: 430px 1fr;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    background: linear-gradient(180deg, #222327, #18191d);
    padding: 8px 12px 16px;
    overflow-y: auto;
}

.tab {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 10px;
}

.tab button {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.75);
    padding: 8px 4px;
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
}

.tab button.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.28);
}

.tabcontent {
    display: none;
}

.panel-stack {
    display: grid;
    gap: 12px;
}

.control-section {
    display: grid;
    gap: 9px;
    padding: 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.section-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.section-heading {
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.72);
}

.mobile-heading {
    display: none;
}

.sidebar-grid {
    display: grid;
    gap: 8px;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 9px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.field span {
    font-size: 17px;
    font-weight: 700;
}

.control-field {
    padding: 8px 9px;
    gap: 4px;
}

.control-field span {
    font-size: 15px;
    font-weight: 700;
}

.compact-field input[type="color"] {
    width: 56px;
    height: 34px;
}

.field-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.guide-link {
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: underline;
    white-space: nowrap;
}

.upload-row {
    align-items: stretch;
}

.upload-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 38px;
}

.upload-file-input {
    width: 112px !important;
    min-width: 112px;
    max-width: 112px;
    flex: 0 0 112px;
    font-size: 0;
    color: transparent;
    overflow: hidden;
}

.upload-file-input::file-selector-button {
    margin-right: 0;
    font-size: 14px;
}

.upload-file-input::-webkit-file-upload-button {
    margin-right: 0;
    font-size: 14px;
}

.upload-checkmark {
    display: none;
    color: #8fe48a;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    line-height: 1;
}

.upload-checkmark.visible {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 12px;
}

.field input[type="range"],
.field input[type="file"],
.field select,
.field textarea {
    width: 100%;
    font-size: 18px;
}

.field textarea {
    resize: vertical;
    min-height: 56px;
}

.inline-control {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.match-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    color: rgba(255, 255, 255, 0.88);
}

.match-toggle input {
    width: 16px;
    height: 16px;
    margin: 0;
}

.status-stack {
    margin-top: 2px;
}

.status-card {
    padding: 9px 11px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    line-height: 1.4;
    font-size: 16px;
}

.status-card.good {
    border-color: rgba(76, 175, 80, 0.7);
}

.status-card.warn {
    border-color: rgba(255, 193, 7, 0.7);
}

.status-card.bad {
    border-color: rgba(244, 67, 54, 0.7);
}

.button-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
}

.button-row button {
    padding: 6px 10px;
    font-size: 12px;
}

.inline-crop-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
}

.inline-crop-controls[hidden],
.inline-crop-overlay[hidden] {
    display: none !important;
}

.inline-crop-controls button {
    background: #ffffff;
    color: #111111;
}

#applyInlineCropBtn {
    background: #4caf50;
    color: #ffffff;
}

.inline-crop-help {
    width: 100%;
    text-align: center;
    margin: 0;
}

button {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 8px 12px;
    background: #ffffff;
    color: #111111;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
}

#downloadButton {
    width: 100%;
    background: #4caf50;
    color: #ffffff;
    margin-top: 10px;
}

#downloadButton:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.tip,
.save-note {
    color: rgba(255, 255, 255, 0.76);
    line-height: 1.4;
    font-size: 16px;
}

.section-tip {
    margin: 0;
    font-size: 14px;
}

.previewArea {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    height: 100vh;
    padding: 12px 26px 26px;
    overflow: hidden;
}

#waveform-wrapper {
    position: sticky;
    top: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-height: calc(100vh - 52px);
}

#waveform-container {
    position: relative;
    width: 100%;
    margin: 0 auto;
    overflow: hidden;
    background: #101010;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
    user-select: none;
    touch-action: none;
}

#waveform-container[data-orientation="wide"] {
    aspect-ratio: 3 / 2;
    width: min(980px, calc(100vw - 500px), calc((100vh - 52px) * 1.5));
}

#waveform-container[data-orientation="portrait"] {
    aspect-ratio: 2 / 3;
    width: min(620px, calc(100vw - 500px), calc((100vh - 52px) * 0.6667));
}

#photoLayer,
#photoImage {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#photoLayer {
    overflow: hidden;
    cursor: grab;
}

#photoLayer.dragging {
    cursor: grabbing;
}

#photoImage {
    object-fit: cover;
}

#photoImage:not([src]),
#photoImage[src=""] {
    display: none;
}

#waveform {
    position: absolute;
    left: 8%;
    width: 84%;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
}

#waveform,
#waveform canvas,
.canvases,
.canvases > div,
.canvases > div > canvas {
    background: transparent !important;
}

#waveformPreviewCanvas {
    position: absolute;
    z-index: 2;
    pointer-events: none;
    background: transparent;
}

.inline-crop-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    touch-action: none;
}

.inline-crop-shade {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.38);
}

.inline-crop-selection {
    position: absolute;
    top: 0;
    bottom: 0;
    border: 1px solid #ff5a5f;
    background: rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
    cursor: grab;
}

.inline-crop-selection:active {
    cursor: grabbing;
}

.inline-crop-handle {
    position: absolute;
    top: -1px;
    bottom: -1px;
    width: 10px;
    background: #ff5a5f;
    border-radius: 999px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.inline-crop-handle.left {
    left: -5px;
    cursor: ew-resize;
}

.inline-crop-handle.right {
    right: -5px;
    cursor: ew-resize;
}

@media (max-width: 920px) {
    #waveform-container {
        touch-action: pan-y;
    }

    #photoLayer {
        touch-action: pan-y;
    }

    .inline-crop-handle {
        top: -2px;
        bottom: -2px;
        width: 18px;
    }

    .inline-crop-handle.left {
        left: -9px;
    }

    .inline-crop-handle.right {
        right: -9px;
    }
}

#overlayText {
    position: absolute;
    left: 7%;
    width: 86%;
    z-index: 3;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.15;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

#watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-24deg);
    z-index: 4;
    color: rgba(255, 255, 255, 0.22);
    letter-spacing: 0.18em;
    font-size: clamp(28px, 4vw, 64px);
    font-weight: 700;
    text-transform: uppercase;
    text-align: center;
    pointer-events: none;
    white-space: nowrap;
}

.save-print-size-message {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.25;
}

.upload-status {
    margin-top: 10px;
    color: #8fe48a;
    font-weight: 700;
    font-size: 17px;
}

.sw-floating-back {
  position: fixed;
  left: 446px;
  bottom: 20px;
  z-index: 5;
  background: rgba(0, 0, 0, 0.88);
  padding: 10px 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  opacity: 0.85;
}

.sw-floating-back:hover {
  opacity: 1;
}

@media (max-width: 1100px) {
    .layout {
        grid-template-columns: 380px 1fr;
    }

    .sw-floating-back {
        left: 396px;
    }

    #waveform-wrapper {
        max-height: calc(100vh - 52px);
    }

    .button-row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 920px) {
    .layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }

    .sw-floating-back {
        left: 20px;
        bottom: 20px;
    }

    .sidebar {
        overflow: visible;
    }

    .previewArea {
        height: auto;
        padding: 18px 12px 32px;
        overflow: visible;
    }

    #waveform-wrapper {
        position: static;
        width: min(96vw, 980px);
        max-height: none;
    }

    #waveform-container[data-orientation="wide"] {
        width: min(96vw, 980px);
    }

    #waveform-container[data-orientation="portrait"] {
        width: min(80vw, 620px);
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .upload-input-row {
        flex-wrap: wrap;
    }

    .button-row {
        grid-template-columns: 1fr;
    }

    .desktop-heading {
        display: none;
    }

    .mobile-heading {
        display: inline;
    }

    .section-heading-row {
        align-items: center;
    }

    .guide-link {
        font-size: 13px;
    }
}
