/* Mobile first: everything sized so it works one-handed on a phone. */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    /* The insets matter once the app is on the home screen: there is no browser
       chrome left to keep it clear of the status bar and the home indicator. */
    padding-top: env(safe-area-inset-top);
    padding-right: calc(12px + env(safe-area-inset-right));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    padding-left: calc(12px + env(safe-area-inset-left));
    background: #1b1d21;
    color: #e8e8ea;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
}

header {
    padding: 12px 0 4px;
    text-align: center;
}

h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.view {
    max-width: 460px;
    margin: 0 auto;
}

.hidden {
    display: none !important;
}

/* Camera */

.camera-frame {
    position: relative;
    margin-top: 12px;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    aspect-ratio: 3 / 4;
}

#preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.camera-message {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    line-height: 1.5;
    color: #b6b8bd;
    background: #000;
}

.camera-message.hidden {
    display: none !important;
}

/* Buttons */

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin: 14px 0;
}

button {
    flex: 1 1 auto;
    min-height: 48px;
    min-width: 88px;
    padding: 0 16px;
    border: 1px solid #3a3d44;
    border-radius: 10px;
    background: #2a2d33;
    color: #e8e8ea;
    font-size: 16px;
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

button:active {
    background: #353941;
}

button:disabled {
    opacity: 0.45;
    cursor: default;
}

button.primary {
    flex-basis: 100%;
    background: #3b7ddd;
    border-color: #3b7ddd;
    font-weight: 600;
}

button.primary:active {
    background: #326ec4;
}

/* Grid */

.status {
    margin: 10px 0;
    min-height: 22px;
    text-align: center;
    font-size: 15px;
    line-height: 1.4;
    color: #b6b8bd;
}

.status.error {
    color: #ff8b7a;
}

.status.ok {
    color: #7ddb96;
}

.grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    aspect-ratio: 1;
    width: 100%;
    margin: 0 auto;
    border: 2px solid #8b8f98;
    border-radius: 4px;
    background: #8b8f98;
    gap: 1px;
    outline: none;
}

.grid:focus-visible {
    box-shadow: 0 0 0 3px rgba(59, 125, 221, 0.6);
}

.cell {
    /* Reset the button defaults: inside the grid these are plain squares. */
    flex: none;
    min-height: 0;
    min-width: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    background: #24272c;
    color: #e8e8ea;
    font-size: clamp(16px, 5.2vw, 26px);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* The 3x3 box separators are drawn as thicker gaps. */
.cell.box-left {
    margin-left: 1px;
}

.cell.box-top {
    margin-top: 1px;
}

.cell.selected {
    background: #35507a;
}

.cell.uncertain {
    background: #4a3b1f;
    color: #ffd479;
}

.cell.conflict {
    background: #5a2626;
    color: #ff9d90;
}

.cell.solved {
    color: #6fb2ff;
    font-weight: 500;
}

.cell.locked {
    cursor: default;
}

/* Keypad */

.keypad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-top: 12px;
}

.keypad button {
    min-width: 0;
    font-size: 20px;
}

.keypad button.wide {
    grid-column: span 5;
    font-size: 16px;
}

/* Debug panel */

.debug {
    margin-top: 16px;
    font-size: 13px;
    color: #9a9da4;
}

.debug summary {
    cursor: pointer;
    padding: 6px 0;
}

.debug canvas {
    max-width: 100%;
    margin-top: 8px;
    border: 1px solid #3a3d44;
    border-radius: 6px;
    image-rendering: pixelated;
}

.debug-cells {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 2px;
    margin-top: 8px;
}

.debug-cells figure {
    margin: 0;
    text-align: center;
}

.debug-cells canvas {
    width: 100%;
    margin: 0;
    border: none;
}

.debug-cells figcaption {
    font-size: 10px;
    line-height: 1.2;
}
