* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    color-scheme: light;
    --bg: #f7f8f2;
    --text: #050505;
    --hint: #202020;
    --button: #fff200;
    --button-text: #050505;
    --surface: #ffffff;
    --line: #050505;
    --safe-top: var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px));
    --safe-right: var(--tg-safe-area-inset-right, env(safe-area-inset-right, 0px));
    --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
    --safe-left: var(--tg-safe-area-inset-left, env(safe-area-inset-left, 0px));
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

button {
    font: inherit;
}

.miniapp {
    position: fixed;
    inset: 0;
    min-height: var(--tg-viewport-stable-height, 100vh);
    background: var(--bg);
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
    padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left));
}

.screen.active {
    display: flex;
}

.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 52px;
}

#sailScreen {
    padding: calc(2px + var(--safe-top)) calc(2px + var(--safe-right)) calc(2px + var(--safe-bottom)) calc(2px + var(--safe-left));
    flex-direction: column;
}

.eyebrow {
    color: var(--hint);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1 {
    margin: 2px 0 0;
    font-size: 1.75rem;
    line-height: 1;
    letter-spacing: 0;
}

.icon-command,
.bar-button {
    border: 3px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-weight: 950;
    min-width: 76px;
    min-height: 54px;
    box-shadow: 0 3px 0 #050505;
}

.sail-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    gap: 0;
}

.hd-upload-panel {
    flex: 0 0 auto;
    display: grid;
    grid-template-rows: 64px 10px;
    gap: 4px;
    padding-top: 4px;
}

.hd-upload-panel.hidden {
    display: none;
}

.hd-upload-button {
    border: 3px solid #050505;
    border-radius: 8px;
    background: #fff200;
    color: #050505;
    font-size: clamp(1.05rem, 3.6vw, 1.5rem);
    font-weight: 950;
    letter-spacing: 0;
    box-shadow: 0 3px 0 #050505;
}

.hd-upload-button.done {
    background: #a8f06a;
}

.hd-upload-button.busy {
    background: #86d8ff;
}

.hd-upload-track {
    width: 100%;
    height: 10px;
    border: 2px solid #050505;
    background: #ffffff;
    overflow: hidden;
}

.hd-upload-progress {
    width: 0%;
    height: 100%;
    background: #050505;
    transition: width 120ms linear;
}

.hd-global-overlay {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(18px + var(--safe-top)) calc(18px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
    background: rgba(255, 242, 0, 0.66);
}

.hd-global-overlay.hidden {
    display: none;
}

.hd-global-panel {
    width: min(88vw, 430px);
    min-height: 430px;
    display: grid;
    grid-template-rows: auto auto minmax(96px, 132px) 24px auto auto 76px 76px;
    align-content: center;
    gap: 12px;
    padding: 24px;
    border: 4px solid #050505;
    background: #ffffff;
    color: #050505;
    text-align: center;
    box-shadow: 0 6px 0 #050505;
}

.hd-global-panel strong {
    font-size: clamp(1.55rem, 7vw, 2.8rem);
    line-height: 1;
    letter-spacing: 0;
}

.hd-global-panel span {
    font-size: clamp(1rem, 4vw, 1.35rem);
    font-weight: 950;
}

#hdGlobalMeta {
    min-height: 1.2em;
    font-size: clamp(0.92rem, 3.4vw, 1.15rem);
}

.hd-global-thumb {
    width: min(100%, 260px);
    height: 132px;
    justify-self: center;
    object-fit: contain;
    border: 3px solid #050505;
    background: #ffffff;
}

.hd-global-thumb.hidden {
    display: none;
}

.hd-global-track {
    width: min(100%, 300px);
    height: 24px;
    justify-self: center;
    border: 3px solid #050505;
    background: #e9e9e9;
    overflow: hidden;
}

.hd-global-progress {
    width: 0%;
    height: 100%;
    background: #86d8ff;
    transition: width 120ms linear;
}

.hd-global-action {
    width: min(100%, 300px);
    min-height: 76px;
    justify-self: center;
    border: 3px solid #050505;
    border-radius: 8px;
    background: #ff4d4d;
    color: #050505;
    font-size: clamp(1rem, 3.7vw, 1.2rem);
    font-weight: 950;
    letter-spacing: 0;
    box-shadow: 0 3px 0 #050505;
}

.hd-global-action:disabled {
    opacity: 1;
    background: #ffffff;
}

.hd-global-action.secondary {
    background: #86d8ff;
}

.hd-global-action.hidden {
    display: none;
}

.locked-screen {
    align-items: center;
    justify-content: center;
    background: #fff200;
}

.locked-panel {
    width: min(88vw, 420px);
    min-height: 220px;
    display: grid;
    align-content: center;
    gap: 18px;
    padding: 28px;
    border: 4px solid #050505;
    background: #ffffff;
    color: #050505;
    text-align: center;
    box-shadow: 0 6px 0 #050505;
}

.locked-panel strong {
    font-size: clamp(1.7rem, 8vw, 3rem);
    line-height: 1;
}

.locked-panel span {
    font-size: clamp(1.05rem, 4vw, 1.4rem);
    font-weight: 950;
    line-height: 1.2;
}

.sail-choice {
    min-width: 0;
    min-height: 0;
    border: 2px solid #050505;
    border-radius: 0;
    color: #050505;
    font-size: clamp(1rem, 3.35vh, 1.62rem);
    font-weight: 900;
    letter-spacing: 0;
}

.sail-group-main {
    background: #fff200;
}

.sail-group-jib {
    background: #ffffff;
}

.sail-group-asym {
    background: #86d8ff;
}

.sail-group-reaching {
    background: #a8f06a;
}

.sail-group-other {
    background: #e9e9e9;
}

.sail-choice:active,
.confirm-tile:active,
.bar-button:active {
    transform: scale(0.985);
}

.confirm-layout {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 0;
    width: 100%;
    height: 100%;
}

.confirm-tile {
    border: 3px solid #050505;
    border-radius: 0;
    color: #050505;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    min-width: 0;
}

.confirm-tile:disabled {
    opacity: 1;
    filter: grayscale(0.35);
}

.confirm-tile strong {
    font-size: clamp(1.45rem, 7vw, 3.2rem);
    line-height: 1.05;
    letter-spacing: 0;
    text-transform: uppercase;
}

.confirm-tile span {
    font-size: clamp(2.2rem, 11vw, 5rem);
    font-weight: 950;
    line-height: 1;
}

.confirm-tile .confirm-spacer {
    height: clamp(1.4rem, 5vw, 2.4rem);
    font-size: 0;
}

.confirm-tile.accept {
    background: #fff200;
}

.confirm-tile.reject {
    background: #ffffff;
}

#uploadHDLater {
    background: #86d8ff;
}

.confirm-tile.location-yacht {
    background: #86d8ff;
}

.confirm-tile.location-chase {
    background: #fff200;
}

.confirm-tile.mode-sailscan {
    background: #fff200;
}

.confirm-tile.mode-yachtshot {
    background: #86d8ff;
}

.camera-screen {
    padding: 0;
    background: #000;
}

#camera,
.snapshot {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.snapshot {
    display: none;
    z-index: 2;
}

.capture-target {
    position: absolute;
    inset: 0;
    z-index: 5;
    border: 0;
    background: transparent;
}

.camera-bar {
    position: absolute;
    z-index: 20;
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
    bottom: calc(10px + var(--safe-bottom));
    display: grid;
    grid-template-columns: 82px 82px 1fr 82px;
    align-items: center;
    gap: 10px;
}

.camera-status {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 3px solid #050505;
    border-radius: 8px;
    background: #ffffff;
    color: #050505;
    font-size: 0.98rem;
    font-weight: 950;
    text-align: center;
    box-shadow: 0 3px 0 #050505;
}

.bar-button.active {
    background: var(--button);
    color: var(--button-text);
}

.grid-overlay {
    position: absolute;
    z-index: 9;
    inset: 0;
    pointer-events: none;
}

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

.grid-overlay span {
    position: absolute;
    background: rgba(255, 242, 0, 0.82);
    box-shadow: 0 0 0 2px #050505;
}

.grid-overlay span:nth-child(1),
.grid-overlay span:nth-child(2) {
    top: 0;
    bottom: 0;
    width: 1px;
}

.grid-overlay span:nth-child(1) {
    left: 33.3333%;
}

.grid-overlay span:nth-child(2) {
    left: 66.6667%;
}

.grid-overlay span:nth-child(3),
.grid-overlay span:nth-child(4) {
    left: 0;
    right: 0;
    height: 1px;
}

.grid-overlay span:nth-child(3) {
    top: 33.3333%;
}

.grid-overlay span:nth-child(4) {
    top: 66.6667%;
}

.data-overlay {
    position: absolute;
    z-index: 10;
    inset: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) calc(72px + var(--safe-bottom)) calc(14px + var(--safe-left));
    pointer-events: none;
    font-size: clamp(1rem, 3.7vw, 1.55rem);
    font-weight: 950;
    line-height: 1.35;
    text-shadow: 0 2px 0 #000, 2px 0 0 #000, -2px 0 0 #000, 0 -2px 0 #000;
    color: #fff34d;
}

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

.data-column {
    position: absolute;
    top: 0;
    display: grid;
    gap: 4px;
}

.data-column.left {
    left: 0;
}

.data-column.right {
    right: 0;
    text-align: right;
}

[data-sail-filter].hidden {
    display: none;
}

.overlay-sail-code {
    position: absolute;
    right: 0;
    bottom: 0;
    padding: 0.32em 0.7em;
    border-radius: 0;
    border: 3px solid #050505;
    background: #fff200;
    color: #050505;
    font-weight: 950;
    text-shadow: none;
}

.camera-screen.yachtshot-mode .data-column.right {
    display: none;
}

.camera-screen.yachtshot-mode .overlay-sail-code {
    background: #86d8ff;
}

.capture-badge {
    position: absolute;
    z-index: 21;
    top: calc(10px + var(--safe-top));
    right: calc(10px + var(--safe-right));
    min-width: 58px;
    height: 38px;
    padding: 0 12px;
    border: 3px solid #050505;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #ffffff;
    color: #050505;
    font-weight: 950;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
}

.capture-badge.hidden {
    display: none;
}

.capture-badge.busy {
    background: #fff200;
    color: #050505;
}

.capture-badge.failed {
    background: #ff4d4d;
    color: #050505;
}

.badge-icon {
    font-size: 1rem;
    line-height: 1;
}

.upload-mask {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 242, 0, 0.92);
    color: #050505;
    font-size: 1.65rem;
    font-weight: 950;
    text-transform: uppercase;
}

.upload-mask.hidden {
    display: none;
}

@media (orientation: landscape) {
    .sail-choice {
        font-size: clamp(0.95rem, 3.6vw, 1.55rem);
    }
}
