/* --- Root Variables & Reset --- */
:root {
    --bg: #121213;
    --tile: #3a3a3c;
    --tile-hover: #4a4a4c;
    --text: #ffffff;
    --accent: #538d4e;
    --error: #b51515;
    --fixed-text: #818384;
    --exponent-bg: #2c2c2e;
    --exponent-text: #aaaaaa;
    --shadow: 0 4px 0 #1a1a1a;
    --transition: 0.15s ease-in-out;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    user-select: none;
}

/* --- Header & Stats --- */
.header {
    text-align: center;
    margin: 10px 0 20px 0;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin: 0;
    letter-spacing: 4px;
    text-transform: uppercase;
}

.stats {
    font-size: 0.85rem;
    color: var(--fixed-text);
    display: flex;
    gap: 25px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-top: 5px;
}

/* --- Active Word Area --- */
#word-area {
    display: flex;
    gap: 12px;
    margin: 40px 0;
    height: 70px;
}

.slot {
    width: 62px;
    height: 62px;
    border: 2px solid var(--tile);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.2rem;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 4px;
    transition: transform var(--transition), border-color var(--transition);
}

.slot.blank {
    border-color: var(--accent);
    cursor: pointer;
}

.slot.filled {
    background-color: var(--accent);
    border-color: var(--accent);
    animation: popIn 0.1s ease-out;
}

.slot.fixed {
    background-color: var(--tile);
    color: var(--fixed-text);
    border-color: transparent;
}

/* --- Tray Sections --- */
.tray-section {
    width: 100%;
    max-width: 450px;
    margin-bottom: 25px;
}

.section-label {
    font-size: 0.65rem;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    margin-bottom: 12px;
    text-align: center;
}

.tray-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
}

/* --- Individual Tiles --- */
.tile-wrapper {
    position: relative;
    width: 52px;
    height: 52px;
}

.tile {
    width: 100%;
    height: 100%;
    background: var(--tile);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.05s, background-color var(--transition);
}

.tile:hover {
    background-color: var(--tile-hover);
}

.tile:active, .tile.pulse {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #1a1a1a;
}

.tile.empty {
    background: transparent;
    border: 2px dashed #2c2c2e;
    box-shadow: none;
    cursor: default;
    color: transparent;
}

.count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--exponent-bg);
    color: var(--exponent-text);
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: 800;
    border: 2px solid var(--bg);
    pointer-events: none;
}

/* --- Messaging & Controls --- */
#message {
    height: 30px;
    line-height: 30px;
    font-weight: 700;
    text-align: center;
    margin: 10px 0;
    font-size: 0.9rem;
    letter-spacing: 1px;
}

.controls {
    margin-top: auto;
    padding-bottom: 40px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 380px;
}

.row {
    display: flex;
    gap: 10px;
}

button {
    padding: 18px;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    font-size: 1.1rem;
    color: white;
    transition: opacity 0.2s, transform 0.1s;
}

button:active {
    transform: scale(0.98);
}

.btn-submit { background: var(--accent); flex: 2; }
.btn-clear { background: var(--tile); flex: 1; }
.btn-giveup {
    background: transparent;
    color: #555;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
}

/* --- Results Screen (Mobile Scrollable) --- */
#game-over {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg);
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Start from top to allow scrolling */
    z-index: 1000;
    padding: 40px 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: fadeIn 0.4s ease-out;
}

#game-over h2 {
    margin-top: 0;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.results-summary-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 40px;
    margin-bottom: 25px;
    flex-shrink: 0;
}

/* Progress Ring */
.score-ring-container {
    position: relative;
    width: 140px;
    height: 140px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.progress-ring {
    position: absolute;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
}

.progress-ring__bar {
    transition: stroke-dashoffset 1.5s ease-out;
    stroke-linecap: round;
    stroke-dasharray: 400; 
    stroke-dashoffset: 400; 
}

.score-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
}

.score-text span { font-size: 3.5rem; font-weight: 900; line-height: 1; color: var(--text); }
.score-text label { font-size: 0.7rem; text-transform: uppercase; color: var(--fixed-text); letter-spacing: 2px; }

/* Metrics Column */
.metrics-column {
    display: flex;
    flex-direction: column;
    gap: 15px;
    border-left: 2px solid var(--tile);
    padding-left: 30px;
    flex-shrink: 0;
}

.metric-box label { font-size: 0.6rem; text-transform: uppercase; color: var(--fixed-text); letter-spacing: 1px; display: block; }
.metric-box span { font-size: 1.8rem; font-weight: 800; color: var(--accent); }

/* --- Global Stats (Floating Bar Chart) --- */
#global-stats-container {
    width: 100%;
    max-width: 320px;
    margin: 0 auto 25px auto;
    text-align: center;
    flex-shrink: 0;
    background: transparent;
}

#global-stats-container h3 {
    font-size: 0.7rem;
    color: var(--fixed-text);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 15px;
}

.stats-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.stats-bar-wrapper {
    flex-grow: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
}

.stats-bar {
    width: 100%;
    background: var(--tile);
    border-radius: 2px 2px 0 0;
    position: relative;
    transition: height 1s ease-out;
    min-height: 2px;
}

.stats-bar.highlight { background: var(--accent); }

.bar-value {
    font-size: 0.55rem;
    color: var(--fixed-text);
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-weight: bold;
}

.stats-label {
    font-size: 0.65rem;
    margin-top: 10px;
    color: var(--fixed-text);
    font-weight: bold;
    width: 100%;
    text-align: center;
}

/* --- Final Word List --- */
#final-word-list-container {
    width: 100%;
    max-width: 320px;
    background: #1a1a1b;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--tile);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 25px;
    flex-shrink: 0;
}

#final-word-list-container h3 {
    font-size: 0.7rem;
    color: var(--fixed-text);
    margin: 0 0 15px 0;
    letter-spacing: 1px;
}

#final-word-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 140px;
    overflow-y: auto;
    justify-content: center;
    margin-bottom: 20px;
    width: 100%;
}

#final-word-list span {
    background: var(--tile);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

#final-word-list::-webkit-scrollbar { width: 4px; }
#final-word-list::-webkit-scrollbar-thumb { background: var(--tile); border-radius: 10px; }

/* --- Footer Buttons --- */
.over-btn { width: 100%; max-width: 250px; margin: 5px 0; flex-shrink: 0; }
.small-btn { font-size: 0.75rem; background: #3a3a3c; width: 220px; }
.blue-btn { background: #1a73e8; }
.green-btn { background: var(--accent); }

/* --- History Log (Main Game Page) --- */
#history-log {
    display: flex;
    overflow-x: auto;
    width: 100%;
    max-width: 500px;
    gap: 10px;
    padding: 15px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--tile) transparent;
}

#history-log::-webkit-scrollbar { height: 4px; display: block; }
#history-log::-webkit-scrollbar-thumb { background: var(--tile); border-radius: 10px; }

.log-entry {
    background: #272729;
    color: var(--fixed-text);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid #333;
}

/* --- Animations --- */
@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- Mobile Specific Overrides --- */
@media (max-width: 480px) {
    .bar-value { font-size: 0.45rem; top: -15px; }
    .stats-label { font-size: 0.5rem; }
    #stats-graph.vertical-chart { min-height: 140px; }
    .results-summary-row { gap: 20px; }
    .metrics-column { padding-left: 20px; }
}
/* Update these specific sections in your style.css */

#stats-graph.vertical-chart {
    display: flex;
    flex-direction: row;
    align-items: flex-end; /* Anchors the bars to the bottom */
    justify-content: center;
    min-height: 160px; 
    height: 160px; /* Force a fixed height for the internal calc */
    width: 100%;
    padding: 30px 0 10px 0;
    gap: 4px;
    box-sizing: border-box;
}

.stats-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%; /* Ensures the column takes up the full 160px */
    justify-content: flex-end; /* Pushes content to the bottom */
}

.stats-bar-wrapper {
    width: 100%;
    height: 100%; /* Important: Gives the bar a vertical area to fill */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    position: relative; /* Anchor for the percentage label */
}

.stats-bar {
    width: 100%;
    background: var(--tile);
    border-radius: 2px 2px 0 0;
    transition: height 1s ease-out;
    min-height: 2px; /* Your baseline */
    /* The height: X% from JS will now work because the parent has 100% height */
}

/* --- Custom Modal Styling --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: var(--bg);
    border: 1px solid var(--tile);
    width: 90%;       /* Flexible width for mobile */
    max-width: 360px; /* Matches your other containers */
    padding: 25px;
    border-radius: 16px;
    text-align: center;
}

#modal-title {
    font-size: 1.8rem;
    margin: 0 0 15px 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent);
}

#modal-body {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text);
    margin-bottom: 25px;
}

.modal-footer {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
    margin-top: 25px;
}

.modal-footer .over-btn {
    width: auto;      /* Removes the 100% width */
    flex: 1;          /* Tells both buttons to share the space equally */
    min-width: 0;     /* Allows them to shrink if necessary */
    max-width: 140px; /* Prevents them from getting too wide on desktop */
    margin: 0;        /* Removes any inherited margins */
    padding: 12px 5px; /* Slightly smaller padding for side-by-side fit */
    font-size: 0.9rem;
}

#modal-cancel-btn {
    background: var(--tile);
}