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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    margin: 0;
    padding: 0;
}

#app {
    max-width: 1400px;
    min-width: 500px;
    margin: 0 auto;
    padding-top: 0;
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ddd;
}

header h1 {
    font-size: 2rem;
    color: #2c3e50;
}

.h2-link {
    font-weight: normal;
    font-size: 75%;
}

.extra-space {
    margin-top: 20px;
}

/* Tabs */
#tabs {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    padding: 8px 12px;
    padding-right: 50px;
    background: #f5f5f5;
    border-bottom: 1px solid #ddd;
    flex-wrap: wrap;
}

.tab-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}

.tab {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 4px 4px 0 0;
    font-size: 14px;
    white-space: nowrap;
}

.tab:hover {
    background: #e0e0e0
}

.tab.active {
    background: white;
    font-weight: 600;
}

/* Tab Content */
.tab-content {
    display: none;
    background: #ffffff;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tab-content.active {
    display: block;
}

/* Controls */
#controls {
    display: flex;
    gap: 20px;
    align-items: stretch;
    margin-bottom: 20px;
    padding: 8px;
    background: #f9f9f9;
    border-radius: 5px;
}

.controls-left {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    flex-shrink: 0;
}

.controls-right {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-left: auto;
    min-width: 0;
    flex-shrink: 1;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.control-group label {
    font-size: 0.9rem;
    font-weight: 500;
}

#date-select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.controls-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: auto;
    justify-content: center;
}

.puzzle-button {
    padding: 8px 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.puzzle-button:hover {
    background: #2980b9;
}

.puzzle-button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

.timer-text {
    font-size: 1.25rem;
    font-family: monospace;
    color: #2c3e50;
    line-height: 1;
}

.solved-label {
    font-size: 0.9rem;
    font-family: sans-serif;
    color: #2c3e50;
}

#timer-container {
    text-align: center;
    margin: 0;
    padding: 0;
    line-height: 1;
}

#timer-display.hidden {
    visibility: hidden;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px 40px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin: 0 0 15px 0;
    color: #27ae60;
    font-size: 2rem;
}

.modal-content p {
    margin: 10px 0;
    font-size: 1.2rem;
    color: #2c3e50;
}

#congratulations-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#congratulations-modal.hidden {
    display: none;
}

#inactivity-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #2c3e50;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#inactivity-modal.hidden {
    display: none;
}

#solve-time {
    font-family: monospace;
    font-size: 1.5rem;
    font-weight: bold;
    color: #3498db;
}

/* Puzzle Display */
#puzzle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

#puzzle-info {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: #666;
}

#puzzle-display {
    width: 100%;
    min-height: 600px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
}

#puzzle-display svg {
    user-select: none;
    -webkit-user-select: none;
}

#puzzle-display svg {
    max-width: 100%;
    max-height: 80vh;
    width: auto;
    height: auto;
}

@keyframes constraint-flash {
    0%, 100% { fill: red; }
    50% { fill: white; }
}

.constraint-flashing {
    animation: constraint-flash 1s infinite;
}

.drag-ghost {
    opacity: 0.8;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

/* Settings Menu */
#settings-btn {
    position: absolute;
    right: 12px;
    top: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #666;
    border-radius: 4px;
}

#settings-btn:hover {
    background: #e0e0e0;
    color: #333;
}

#settings-dropdown {
    position: absolute;
    top: 45px;
    right: 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 180px;
    z-index: 100;
}

#settings-dropdown.hidden {
    display: none;
}

#settings-dropdown h3 {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: #666;
}

.setting-item {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

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

.setting-item label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
}

.setting-item select {
    width: 100%;
    padding: 6px;
    margin-top: 4px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

/* Solutions Tab Layout */
.solutions-layout {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.solutions-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 150px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
}

.radio-group.vertical {
    flex-direction: column;
    gap: 5px;
}

.solutions-unsolved {
    flex: 1;
    min-height: 300px;
    display: flex;
    flex-direction: column;
}

#sol-unsolved-display {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
    background: white;
    border-radius: 5px;
    border: 1px solid #ddd;
}

#sol-unsolved-display svg {
    max-width: 100%;
    max-height: 400px;
    width: auto;
    height: auto;
}

/* Solutions Area */
.solutions-area {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #ddd;
}

.solutions-area.hidden {
    display: none;
}

.solutions-header {
    text-align: center;
    margin-bottom: 8px;
    margin-top: 0;
    color: #666;
}

.solutions-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

.sol-nav-btn {
    padding: 10px 8px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.sol-nav-btn:hover:not(:disabled) {
    background: #e0e0e0;
}

.sol-nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.solutions-panels {
    display: flex;
    gap: 10px;
    flex: 1;
    justify-content: center;
}

.solution-panel {
    flex: 0 1 45%;
    min-height: 200px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
    padding: 8px;
}

.solution-panel svg {
    max-width: 100%;
    max-height: 350px;
    width: auto;
    height: auto;
}

.solution-panel.single {
    flex: 0 1 90%;
    max-width: 90%;
}

.solution-panel.lone {
    /* Same size as normal, but centered */
    flex: 0 1 45%;
    max-width: 45%;
    margin: 0 auto;
}

#sol-date-select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

#sol-load-puzzle,
#sol-show-solutions {
    padding: 8px 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

#sol-load-puzzle:hover,
#sol-show-solutions:hover {
    background: #2980b9;
}

#sol-load-puzzle:disabled,
#sol-show-solutions:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

/* Email Tab Layout */
#email-form-container {
    margin-top: 30px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 5px;
}

.email-select {
    width: 100%;
    max-width: 400px;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

.form-group.hidden {
    display: none;
}

.form-group input[type="time"] {
    width: auto;
    max-width: 200px;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

.form-group input[type="email"] {
    width: 100%;
    max-width: 400px;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

#email-error {
    margin: 10px 0;
}

#email-error.hidden {
    display: none;
}

#email-status-container {
    margin-top: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
}

#email-status-container.hidden {
    display: none;
}

/* About Tab Layout */
.sync-section {
    margin-top: 30px;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 5px;
}

.sync-link-container {
    display: flex;
    gap: 10px;
    margin: 10px 0;
}

.sync-link-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: monospace;
    background: white;
}

.copy-btn {
    padding: 8px 16px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.copy-btn:hover {
    background: #2980b9;
}

.copy-btn.copied {
    background: #27ae60;
}

.sync-note {
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

.sync-warning {
    color: #e67e22;
    font-weight: 500;
}

/* Messages */
.error {
    color: #e74c3c;
    padding: 10px;
    background: #ffeaea;
    border-radius: 4px;
    margin: 10px 0;
}

.loading {
    color: #666;
    font-style: italic;
}

@media (max-width: 600px) {
    #app {
        min-width: 0 !important;
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    /* Solutions tab: stack layout vertically */
    .solutions-layout {
        flex-direction: column !important;
    }

    /* Solutions controls: horizontal like Play tab */
    .solutions-controls {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        align-items: flex-end !important;
        min-width: 0 !important;
    }

    /* Difficulty radio group: horizontal on mobile */
    .solutions-controls .radio-group.vertical {
        flex-direction: row !important;
        gap: 15px !important;
    }

    /* Solution panels: stack vertically */
    .solutions-panels {
        flex-direction: column !important;
        align-items: center !important;
    }

    .solution-panel {
        flex: 0 1 100% !important;
        max-width: 100% !important;
    }

    #settings-dropdown {
        width: calc(100vw - 40px) !important;
        right: 10px !important;
    }

    /* Play tab: stack controls vertically */
    #controls {
        flex-direction: column !important;
    }

    .controls-left {
        justify-content: center !important;
    }

    .controls-right {
        width: 100% !important;
        align-items: center !important;
    }

    .controls-buttons {
        justify-content: center !important;
    }

    .puzzle-button {
        padding: 6px 8px !important;
        font-size: 0.9rem !important;
    }

    .sol-nav-btn {
        padding: 6px 8px !important;
        font-size: 0.9rem !important;
    }

    #date-select,
    #sol-date-select,
    #sol-load-puzzle,
    #sol-show-solutions {
	padding: 6px 8px;
	font-size: 0.9rem;
    }

    .timer-text {
        font-size: 1.1rem !important;
    }

    dl {
        grid-template-columns: 1fr !important;
        gap: 2px 20px !important;
    }

    dt {
        margin-top: 10px;
    }

    dt:first-child {
        margin-top: 0;
    }

    dd {
        margin-left: 10px !important;
    }
}

/* Description List */
dl {
  display: grid;
  grid-template-columns: max-content auto;
  gap: 10px 20px;
}

dt { font-weight: bold; }

dd { margin: 0; }
