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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    min-height: 100vh;
    color: #fff;
}

.screen { min-height: 100vh; display: flex; flex-direction: column; }
.screen.hidden { display: none !important; }

/* ===== Settings ===== */
.settings-container {
    max-width: 620px; margin: auto; padding: 40px;
    background: rgba(0,0,0,0.3); border-radius: 20px; text-align: center;
}
.settings-container h1 {
    font-size: 3.2rem; margin-bottom: 8px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}
.settings-container h2 {
    font-size: 1.9rem; margin-bottom: 35px;
    font-weight: normal; opacity: 0.9;
}

.setting-group { margin-bottom: 28px; }
.setting-group > label { display: block; font-size: 1.4rem; margin-bottom: 18px; }

.button-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}
.setting-btn {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 16px 12px;
    border: 3px solid #fff; background: transparent; color: #fff;
    border-radius: 14px; cursor: pointer; transition: all 0.2s;
    min-height: 85px;
}
.setting-btn:hover  { background: rgba(255,255,255,0.18); transform: scale(1.05); }
.setting-btn:focus  { outline: 4px solid #f39c12; outline-offset: 2px; }
.setting-btn.active { background: #fff; color: #2c3e50; font-weight: bold; }
.disc-count { font-size: 2rem; font-weight: bold; }
.diff-hint  { font-size: 0.82rem; opacity: 0.75; font-weight: normal; }
.setting-btn.active .diff-hint { opacity: 0.6; }

.rules-summary {
    background: rgba(255,255,255,0.1); border-radius: 12px;
    padding: 18px 22px; margin: 22px 0; text-align: left;
}
.rules-summary h3 { font-size: 1.3rem; margin-bottom: 10px; }
.rules-summary ul  { list-style: none; }
.rules-summary li  { font-size: 1.05rem; padding: 5px 0; opacity: 0.9; }
.rules-summary li::before { content: '• '; color: #f39c12; font-weight: bold; }

.primary-btn {
    margin-top: 20px; padding: 20px 50px; font-size: 1.8rem;
    background: #e74c3c; color: #fff; border: none; border-radius: 15px;
    cursor: pointer; font-weight: bold; transition: all 0.2s;
    min-height: 70px; display: block; width: 100%;
}
.primary-btn:hover  { background: #c0392b; transform: scale(1.03); box-shadow: 0 5px 20px rgba(231,76,60,0.5); }
.primary-btn:focus  { outline: 4px solid #f39c12; outline-offset: 3px; }
.secondary-btn { margin-top: 15px; background: rgba(255,255,255,0.2); border: 3px solid #fff; }
.secondary-btn:hover { background: rgba(255,255,255,0.35); transform: scale(1.03); box-shadow: none; }

/* ===== Game Header ===== */
.game-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 25px; background: rgba(0,0,0,0.3);
    flex-wrap: wrap; gap: 10px; min-height: 80px;
}
.header-left { display: flex; align-items: center; gap: 14px; }
.game-header h1 { font-size: 1.8rem; }
.info-badge {
    background: rgba(255,255,255,0.2); border-radius: 8px;
    padding: 5px 14px; font-size: 1rem; font-weight: bold;
}
.header-center { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.header-right   { display: flex; gap: 12px; flex-wrap: wrap; }

/* Stats row */
.stats-row {
    display: flex; gap: 20px; align-items: center;
}
.stat-block {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    background: rgba(255,255,255,0.12); border-radius: 10px;
    padding: 6px 16px; min-width: 70px;
}
.stat-label { font-size: 0.78rem; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 1.4rem; font-weight: bold; font-variant-numeric: tabular-nums; }
.timer { letter-spacing: 1px; }

/* Status message */
.status-msg {
    font-size: 1.1rem; opacity: 0.9;
    background: rgba(255,255,255,0.12); border-radius: 8px;
    padding: 5px 18px; text-align: center; min-width: 260px;
    transition: all 0.2s;
}
.status-msg.has-disc {
    background: rgba(243,156,18,0.3); border: 2px solid rgba(243,156,18,0.6);
    font-weight: bold;
}
.status-msg.error {
    background: rgba(231,76,60,0.35); border: 2px solid rgba(231,76,60,0.7);
    animation: shake 0.35s ease;
}
@keyframes shake {
    0%,100% { transform: translateX(0); }
    25%      { transform: translateX(-8px); }
    75%      { transform: translateX(8px); }
}

.action-btn {
    padding: 14px 22px; font-size: 1.1rem;
    background: rgba(255,255,255,0.9); color: #2c3e50;
    border: none; border-radius: 10px; cursor: pointer;
    font-weight: bold; transition: all 0.2s; min-height: 52px;
    white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.action-btn:hover { background: #fff; transform: scale(1.05); }
.action-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }
a.action-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* ===== Game Area ===== */
.game-area {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: flex-end;
    padding: 20px 20px 10px;
    gap: 12px;
}

/* ===== Hanoï Board ===== */
.hanoi-board {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 0;
    width: 100%;
    max-width: 860px;
    background: linear-gradient(to bottom, rgba(60,35,15,0.6) 0%, rgba(40,20,5,0.8) 100%);
    border-radius: 20px;
    padding: 16px 8px 0;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,200,100,0.15);
    border: 1px solid rgba(180,120,40,0.3);
}

/* ===== Peg Container ===== */
.peg-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    cursor: pointer;
    padding: 8px 6px 0;
    border-radius: 16px;
    border: 3px solid transparent;
    transition: border-color 0.2s, background 0.2s;
    outline: none;
    /* Minimum touch target */
    min-height: 200px;
}
.peg-container:hover  { background: rgba(255,255,255,0.05); }
.peg-container:focus  { border-color: #f39c12; background: rgba(243,156,18,0.08); }
.peg-container.selected-source {
    border-color: #f39c12;
    background: rgba(243,156,18,0.14);
    box-shadow: inset 0 0 20px rgba(243,156,18,0.08);
}
.peg-container.valid-target {
    border-color: #2ecc71;
    background: rgba(46,204,113,0.1);
    box-shadow: inset 0 0 20px rgba(46,204,113,0.06);
}
.peg-container.invalid-target {
    border-color: #e74c3c;
    background: rgba(231,76,60,0.1);
    animation: shake 0.35s ease;
}

/* ===== Disc Area ===== */
.discs-area {
    display: flex;
    flex-direction: column-reverse; /* bottom disc = index 0 = rendered first = at bottom */
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    /* height = nDiscs * discHeight, set by JS */
    position: relative;
    z-index: 2;
    gap: 3px;
    padding-bottom: 3px;
}

/* ===== Pole ===== */
.pole {
    width: 16px;
    background: linear-gradient(to right,
        #7a5010 0%, #c8921a 18%, #e8be5a 35%,
        #d4a030 50%, #c8921a 65%, #e8be5a 82%, #7a5010 100%);
    border-radius: 8px 8px 0 0;
    box-shadow: 2px 0 6px rgba(0,0,0,0.4), -1px 0 3px rgba(255,220,80,0.15);
    /* height set by JS to match disc area + some extra */
    position: absolute;
    bottom: 22px; /* sits on the base */
    z-index: 1;
    left: 50%; transform: translateX(-50%);
}

/* ===== Base ===== */
.peg-base {
    width: 88%;
    height: 22px;
    background: linear-gradient(to bottom,
        #c89030 0%, #a07020 30%, #7a5010 70%, #5a3800 100%);
    border-radius: 11px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.55), inset 0 2px 4px rgba(255,200,80,0.25),
        inset 0 -2px 4px rgba(0,0,0,0.3);
    position: relative;
    z-index: 3;
    flex-shrink: 0;
}

/* ===== Board wrapper + Peg Labels ===== */
.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 860px;
}
.peg-labels-row {
    display: flex;
    width: 100%;
    padding: 0 8px; /* match board horizontal padding */
    margin-top: 8px;
}
.peg-label {
    flex: 1;
    text-align: center;
    font-size: 1.6rem; font-weight: bold;
    text-shadow: 0 2px 6px rgba(0,0,0,0.6);
    letter-spacing: 1px;
}

/* ===== Discs ===== */
.disc {
    height: var(--disc-h);
    width: var(--disc-w);
    border-radius: calc(var(--disc-h) / 2);
    display: flex; align-items: center; justify-content: center;
    font-size: calc(var(--disc-h) * 0.42);
    font-weight: bold;
    color: rgba(255,255,255,0.9);
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
    box-shadow:
        0 6px 14px rgba(0,0,0,0.5),
        inset 0 3px 6px rgba(255,255,255,0.35),
        inset 0 -3px 6px rgba(0,0,0,0.25);
    transition: transform 0.15s, box-shadow 0.15s;
    cursor: pointer;
    user-select: none;
    position: relative;
    flex-shrink: 0;
    border-top: 2px solid rgba(255,255,255,0.3);
    border-bottom: 2px solid rgba(0,0,0,0.2);
}
.disc:hover  {
    transform: scaleY(1.1);
    box-shadow: 0 8px 20px rgba(0,0,0,0.55), inset 0 3px 6px rgba(255,255,255,0.4), inset 0 -3px 6px rgba(0,0,0,0.25);
}
.disc.top-disc { cursor: pointer; }
.disc.selected-disc {
    outline: 4px solid #f39c12;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px #f39c12, 0 10px 24px rgba(243,156,18,0.6),
        inset 0 3px 6px rgba(255,255,255,0.35), inset 0 -3px 6px rgba(0,0,0,0.25);
    transform: translateY(-8px) scaleY(1.06);
    z-index: 10;
}
.disc.just-placed {
    animation: place-bounce 0.38s ease-out;
}
@keyframes place-bounce {
    0%   { transform: translateY(-44px); opacity: 0.7; }
    55%  { transform: translateY(5px); }
    75%  { transform: translateY(-4px); }
    90%  { transform: translateY(2px); }
    100% { transform: translateY(0); opacity: 1; }
}

/* Disc colors — rainbow arc from smallest (1) to largest (8) */
.disc[data-size="1"] { background: linear-gradient(160deg, #ff6b9d, #e91e63, #c2185b); }
.disc[data-size="2"] { background: linear-gradient(160deg, #ce93d8, #9c27b0, #7b1fa2); }
.disc[data-size="3"] { background: linear-gradient(160deg, #7986cb, #3f51b5, #283593); }
.disc[data-size="4"] { background: linear-gradient(160deg, #64b5f6, #2196f3, #1565c0); }
.disc[data-size="5"] { background: linear-gradient(160deg, #4db6ac, #009688, #00695c); }
.disc[data-size="6"] { background: linear-gradient(160deg, #81c784, #4caf50, #2e7d32); }
.disc[data-size="7"] { background: linear-gradient(160deg, #ffb74d, #ff9800, #e65100); }
.disc[data-size="8"] { background: linear-gradient(160deg, #ef9a9a, #f44336, #b71c1c); }

/* ===== Keyboard Hint ===== */
.keyboard-hint {
    font-size: 1rem; opacity: 0.6; text-align: center; margin-top: 4px;
}
kbd {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 6px;
    padding: 1px 8px;
    font-family: monospace;
    font-size: 1rem;
}

/* ===== Win Screen ===== */
.result-container {
    max-width: 520px; margin: auto; padding: 50px 40px;
    background: rgba(0,0,0,0.4); border-radius: 20px; text-align: center;
    border: 3px solid #f39c12;
}
.trophy   { font-size: 5rem; margin-bottom: 10px; }
.result-container h1 { font-size: 3rem; margin-bottom: 12px; }
.result-container > p { font-size: 1.5rem; opacity: 0.9; margin-bottom: 25px; }

.win-stats {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 14px; margin-bottom: 30px;
}
.win-stat {
    background: rgba(255,255,255,0.1); border-radius: 12px;
    padding: 14px 10px; display: flex; flex-direction: column; gap: 5px;
}
.win-stat-label { font-size: 0.9rem; opacity: 0.75; }
.win-stat-value { font-size: 1.8rem; font-weight: bold; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .game-header   { justify-content: center; }
    .header-left   { width: 100%; justify-content: center; }
    .header-center { width: 100%; }
    .header-right  { width: 100%; justify-content: center; }
    .stats-row     { gap: 10px; }
    .stat-block    { padding: 5px 10px; min-width: 55px; }
    .peg-label     { font-size: 1.3rem; }
    .peg-labels-row { margin-top: 6px; }
    .button-grid   { grid-template-columns: repeat(3, 1fr); gap: 10px; }
}
@media (max-width: 480px) {
    .hanoi-board { gap: 0; }
    .peg-container { padding: 6px 3px 0; }
    .keyboard-hint { display: none; }
    .win-stats { grid-template-columns: 1fr 1fr; }
}
