/* 
   Himitsu-Bako (箱根 秘密箱) - Japanese Wooden Puzzle Box Experience
   Aesthetic: Wabi-sabi minimalist luxury, dark charcoal slate, gold kintsugi accents, antique washi parchment.
*/

:root {
    --bg-dark: #0f0e0e;
    --bg-panel: rgba(22, 19, 18, 0.88);
    --bg-panel-subtle: rgba(30, 26, 24, 0.7);
    --border-gold: rgba(212, 175, 55, 0.35);
    --border-gold-bright: #d4af37;
    --text-main: #f3efe6;
    --text-muted: #a39b8e;
    --text-gold: #e8c86b;
    --accent-red: #c53030;
    --font-serif: 'Cinzel', 'Noto Serif JP', 'Georgia', serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.65);
    --shadow-gold: 0 0 16px rgba(212, 175, 55, 0.25);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 14px;
}

/* 3D WebGL Canvas Container */
#webgl-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    cursor: grab;
}

#webgl-container:active {
    cursor: grabbing;
}

/* Main UI Layer (Overlay) */
.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 24px;
}

/* Top Header Bar */
.top-header {
    pointer-events: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.brand {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-gold);
    border-radius: 8px;
    padding: 12px 18px;
    box-shadow: var(--shadow-soft);
    flex-shrink: 0;
}

.brand-kanji {
    font-family: var(--font-serif);
    font-size: 18px;
    letter-spacing: 4px;
    color: var(--text-gold);
    margin-bottom: 2px;
}

.brand-title {
    font-family: var(--font-serif);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-main);
}

.brand-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.3;
}

/* Interlocking Sequence Widget (Docked in Header) */
.step-status-widget {
    pointer-events: auto;
    background: var(--bg-panel);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border-gold);
    border-radius: 8px;
    padding: 10px 18px;
    box-shadow: var(--shadow-soft);
    min-width: 280px;
    max-width: 420px;
    flex: 1;
}

.hud-progress-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.widget-label {
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 500;
}

.hud-steps {
    font-family: var(--font-serif);
    font-size: 13px;
    color: var(--text-gold);
    font-weight: 600;
}

.progress-track {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
    border: 1px solid rgba(212, 175, 55, 0.2);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #b87233, #d4af37);
    border-radius: 3px;
    transition: width 0.35s ease;
}

.hud-desc {
    font-size: 11.5px;
    line-height: 1.4;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.solved-badge {
    color: var(--text-gold);
    font-weight: 600;
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

.top-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Glassmorphic Buttons */
.btn-glass {
    pointer-events: auto;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-gold);
    color: var(--text-main);
    padding: 8px 14px;
    border-radius: 6px;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-soft);
}

.btn-glass:hover {
    background: rgba(45, 38, 33, 0.95);
    border-color: var(--border-gold-bright);
    color: var(--text-gold);
    box-shadow: var(--shadow-gold);
    transform: translateY(-1px);
}

.btn-glass:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, #7c4c1a, #523110);
    border-color: var(--border-gold-bright);
    color: #fff;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #995f23, #6b4016);
}

/* Bottom Control Deck */
.bottom-deck {
    pointer-events: auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
}

.action-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.generator-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-gold);
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: var(--shadow-soft);
    display: flex;
    align-items: center;
    gap: 12px;
}

.gen-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gen-group label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
}

.gen-group select {
    background: #1e1916;
    border: 1px solid var(--border-gold);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

.gen-group select:focus {
    border-color: var(--border-gold-bright);
}

/* Floating Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30, 24, 20, 0.95);
    border: 1px solid var(--border-gold-bright);
    color: var(--text-gold);
    padding: 9px 20px;
    border-radius: 6px;
    font-size: 12.5px;
    box-shadow: var(--shadow-soft);
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 100;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 8, 8, 0.82);
    backdrop-filter: blur(10px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* Ancient Japanese Washi Parchment Scroll Style */
.parchment-scroll {
    background: #f4ecd8;
    background-image: radial-gradient(#ebe0c5 15%, transparent 16%), radial-gradient(#ded1b0 15%, transparent 16%);
    background-size: 30px 30px;
    background-position: 0 0, 15px 15px;
    color: #2b1f17;
    border: 8px solid #5a391c;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.9), inset 0 0 60px rgba(120, 80, 40, 0.2);
    border-radius: 4px;
    width: 100%;
    max-width: 540px;
    padding: 36px 32px;
    text-align: center;
    position: relative;
    transform: scale(0.92);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-backdrop.active .parchment-scroll {
    transform: scale(1);
}

.scroll-header-ribbon {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: #8c4424;
    font-weight: 700;
    margin-bottom: 18px;
    border-bottom: 1px solid rgba(140, 68, 36, 0.3);
    padding-bottom: 8px;
}

.scroll-kanji {
    font-family: var(--font-serif);
    font-size: 38px;
    letter-spacing: 6px;
    color: #1a120c;
    margin: 12px 0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.15);
}

.scroll-romaji {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 16px;
    color: #613e28;
    margin-bottom: 14px;
}

.scroll-meaning {
    font-size: 15px;
    line-height: 1.7;
    color: #2b1f17;
    margin: 16px 0 20px 0;
}

.scroll-author {
    font-size: 12px;
    color: #7a5840;
    font-style: italic;
}

.scroll-custom-tag {
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #991b1b;
    font-weight: bold;
    margin-bottom: 12px;
}

.scroll-custom-body {
    font-size: 16px;
    line-height: 1.8;
    color: #1e130a;
    font-weight: 500;
    margin: 20px 0;
    padding: 16px;
    background: rgba(255, 255, 255, 0.4);
    border-left: 3px solid #991b1b;
    border-radius: 4px;
    word-break: break-word;
}

.scroll-footer {
    font-size: 11px;
    color: #8a6c55;
    margin-top: 14px;
}

.modal-close-btn {
    margin-top: 24px;
    background: #3b2413;
    color: #f7ebd3;
    border: none;
    padding: 10px 24px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-close-btn:hover {
    background: #54351d;
}

/* Craft Modal Dialog */
.craft-dialog {
    background: var(--bg-panel);
    border: 1px solid var(--border-gold-bright);
    border-radius: 8px;
    padding: 28px;
    max-width: 500px;
    width: 100%;
    box-shadow: var(--shadow-soft);
}

.craft-dialog h3 {
    font-family: var(--font-serif);
    font-size: 18px;
    color: var(--text-gold);
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.craft-dialog p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 18px;
    line-height: 1.5;
}

.craft-dialog textarea {
    width: 100%;
    height: 90px;
    background: #1a1614;
    border: 1px solid var(--border-gold);
    border-radius: 6px;
    color: var(--text-main);
    padding: 10px;
    font-family: var(--font-sans);
    font-size: 13px;
    resize: none;
    outline: none;
    margin-bottom: 14px;
}

.craft-dialog textarea:focus {
    border-color: var(--border-gold-bright);
}

.craft-dialog select {
    width: 100%;
    background: #1a1614;
    border: 1px solid var(--border-gold);
    border-radius: 6px;
    color: var(--text-main);
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
    margin-bottom: 18px;
}

.share-link-box {
    margin-top: 16px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    border: 1px dashed var(--border-gold);
}

.share-link-box input {
    width: 100%;
    background: #0d0b0a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-gold);
    padding: 8px;
    font-size: 12px;
    border-radius: 4px;
    margin-bottom: 8px;
}

/* Mobile Responsiveness */
@media (max-width: 900px) {
    .ui-layer {
        padding: 14px;
    }
    .top-header {
        flex-direction: column;
        align-items: stretch;
    }
    .bottom-deck {
        flex-direction: column;
        align-items: stretch;
    }
    .generator-panel {
        flex-wrap: wrap;
    }
    .brand {
        max-width: 100%;
    }
    .step-status-widget {
        max-width: 100%;
    }
}
