:root {
    --bg-color: #f6f7f9;
    --surface-color: #ffffff;
    --primary-color: #4a69ff;
    --text-color: #2e333d;
    --text-secondary-color: #8a919f;
    --border-color: #e4e6ea;
    --shadow-color: rgba(46, 51, 61, 0.1);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
}

.app-header {
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    box-shadow: 0 2px 8px var(--shadow-color);
}
.nav-container {
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 60px;
}
.nav-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
    text-decoration: none;
}
.nav-brand:hover {
    color: var(--primary-color);
}

.app-wrapper {
    width: 100%;
    max-width: 1100px; /* Increased max-width for new column */
    margin: 40px auto;
    display: grid;
    grid-template-columns: 140px 1fr 280px; /* New: Nav column, Tool Panel, History Panel */
    gap: 40px;
    padding: 0 24px;
    align-items: start; /* Ensure columns can have independent heights */
}

/* --- Left Vertical Nav: Tool Selector --- */
.tool-selector {
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column; /* Vertical layout */
    gap: 8px;
}
.tool-selector .tool-btn {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary-color);
    background: transparent;
    border: none;
    border-radius: var(--radius-md); /* Slightly larger radius for active state */
    padding: 12px 10px; /* Adjust padding for vertical */
    text-align: left; /* Align text left */
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}
.tool-selector .tool-btn.active {
    background-color: var(--primary-color);
    color: #ffffff;
}

/* --- Left: Tool Panel --- */
.tool-panel {
    display: flex;
    justify-content: center;
}

/* ... existing styles ... */

.result-display {
    width: 380px; /* Increased size */
    height: 380px; /* Increased size */
    background-color: var(--surface-color);
    box-shadow: 0 4px 16px var(--shadow-color);
    font-size: 7rem; /* Increased font size */
    font-weight: 700;
    color: var(--primary-color);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease, clip-path 0.3s ease-in-out;
    overflow: hidden;
}
.result-display:active {
    transform: scale(0.98);
    box-shadow: 0 2px 8px var(--shadow-color);
}

/* Shape Modifiers */
.result-display.shape-round { border-radius: 50%; }
.result-display.shape-square { border-radius: var(--radius-lg); }
.result-display.shape-rect { border-radius: var(--radius-lg); }
/* Clip-path Shapes for Dice */
.shape-d4 { clip-path: polygon(50% 0%, 5% 100%, 95% 100%); }
.shape-d6 { border-radius: var(--radius-lg); } /* Just a square */
.shape-d8 { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.shape-d10 { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); } /* Same as d8 */
.shape-d12 { clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); }
.result-display.shape-d20 { clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%); }

.result-display--pips {
    font-size: 0 !important; /* Override parent font size to allow pip grid to render */
}

.text-result {
    min-height: 24px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-secondary-color);
}

/* --- Right: History Panel --- */
.history-panel {
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: 0 4px 24px var(--shadow-color);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto; /* Header, STRETCHY list, footer */
    max-height: calc(100vh - 100px); /* Hard limit to prevent page growth */
    gap: 16px;
}
.history-panel h2 {
    margin: 0;
    font-size: 1.25rem;
}
.history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto; /* Make it scrollable */
}
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border-color);
    animation: fadeIn 0.4s ease;
}
.history-item:first-child {
    padding-top: 0;
}
.history-item-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0; /* Prevents flex item from overflowing */
}
.history-item-icon {
    font-size: 1.1rem;
}
.history-item-text {
    font-size: 1rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item-time {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary-color);
    flex-shrink: 0;
}

.clear-btn {
    margin-top: 16px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary-color);
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.clear-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}


/* --- Controls & Visuals --- */
.controls { display: none; }
.controls.active { display: block; animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dice-grid, .number-range, textarea {
    padding: 12px;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px var(--shadow-color);
}
.dice-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.dice-btn {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px 0;
    cursor: pointer;
    transition: all 0.2s ease;
}
.dice-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}
.dice-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
}

/* Same visuals from previous step, they were good */
.coin-flipper {
    width: 100%;
    height: 100%;
    display: flex; /* Centering the letter */
    justify-content: center;
    align-items: center;
}
/* No more 3D transform properties */
.coin-letter {
    font-size: 5rem; /* Larger font size */
    font-weight: 700;
    color: rgba(0,0,0,0.3); /* Subtler color */
    line-height: 1;
    user-select: none;
    transition: none; /* No transition on content change */
}

.dice-pips-container { width: 70%; height: 70%; display: grid; padding: 10%; gap: 15%; grid-template-rows: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr); }
.pip {
    background-color: var(--primary-color);
    border-radius: 50%;
}
.pip:nth-child(1) { grid-area: 1 / 1; } .pip:nth-child(2) { grid-area: 1 / 3; } .pip:nth-child(3) { grid-area: 3 / 1; } .pip:nth-child(4) { grid-area: 3 / 3; } .pip:nth-child(5) { grid-area: 1 / 2; } .pip:nth-child(6) { grid-area: 2 / 1; } .pip:nth-child(7) { grid-area: 2 / 3; } .pip:nth-child(8) { grid-area: 3 / 2; } .pip:nth-child(9) { grid-area: 2 / 2; }
.dice-pips-container .pip { display: none; }
.pip-1 .pip:nth-child(9) { display: block; } .pip-2 .pip:nth-child(1), .pip-2 .pip:nth-child(4) { display: block; } .pip-3 .pip:nth-child(1), .pip-3 .pip:nth-child(9), .pip-3 .pip:nth-child(4) { display: block; } .pip-4 .pip:nth-child(1), .pip-4 .pip:nth-child(2), .pip-4 .pip:nth-child(3), .pip-4 .pip:nth-child(4) { display: block; } .pip-5 .pip:nth-child(1), .pip-5 .pip:nth-child(2), .pip-5 .pip:nth-child(3), .pip-5 .pip:nth-child(4), .pip-5 .pip:nth-child(9) { display: block; } .pip-6 .pip:nth-child(1), .pip-6 .pip:nth-child(2), .pip-6 .pip:nth-child(3), .pip-6 .pip:nth-child(4), .pip-6 .pip:nth-child(6), .pip-6 .pip:nth-child(7) { display: block; }

.number-range, textarea {
    border: 1px solid var(--border-color);
    font-size: 1.1rem;
    padding: 16px;
}
.number-range input { background: transparent; border: none; color: var(--text-color); font-size: inherit; font-weight: 600; width: 40%; text-align: center; }
.number-range input:focus, textarea:focus { outline: none; }
textarea { width: 100%; height: 120px; resize: vertical; }

.card-options {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px var(--shadow-color);
}
.card-options label {
    font-weight: 600;
}
.card-options input {
    width: 60px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 1rem;
}

.card-visual-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 10px;
    width: 100%;
    height: 100%;
}
.card-visual {
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    width: 100px;
    height: 140px;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 0.9;
}
.corner.top-left {
    top: 8px;
    left: 8px;
}
.corner.bottom-right {
    bottom: 8px;
    right: 8px;
    transform: rotate(180deg);
}
.card-rank {
    font-size: 1.5rem;
    font-weight: 600;
}
.card-suit {
    font-size: 1rem;
}
.suit-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3.5rem;
    opacity: 0.8;
}
.card-suit.red { color: #d92a2a; }
.card-suit.black { color: #222; }
.card-rank.red { color: #d92a2a; }
.card-rank.black { color: #222; }

.secondary-btn {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary-color);
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 12px;
}
.secondary-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.remaining-items-container {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}
.remaining-items-container h4 {
    margin: 0 0 8px;
    font-size: 0.9rem;
    color: var(--text-secondary-color);
}
#drawerRemainingList {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.95rem;
    color: var(--text-color);
}
#drawerRemainingList li {
    padding: 4px 0;
}

/* --- Details/Progressive Disclosure --- */
.details-placeholder {
    margin-top: 24px;
}
details {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--surface-color);
    box-shadow: 0 2px 8px var(--shadow-color);
}
summary {
    list-style: none; /* Remove default marker */
    padding: 12px 16px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary-color);
}
summary::-webkit-details-marker {
    display: none;
}
summary:before {
    content: '►';
    margin-right: 8px;
    font-size: 0.8em;
    transition: transform 0.2s ease-in-out;
}
details[open] > summary:before {
    transform: rotate(90deg);
}
.details-content {
    padding: 0 16px 16px;
    border-top: 1px solid var(--border-color);
}
.details-content h4 {
    margin: 16px 0 8px;
    font-size: 1rem;
    color: var(--text-color);
}
.details-content p, .details-content ul {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-secondary-color);
    margin: 0 0 1em;
}
.details-content ul {
    padding-left: 20px;
}
.details-content a {
    color: var(--primary-color);
    text-decoration: none;
}
.details-content a:hover {
    text-decoration: underline;
}
.details-content code {
    font-family: monospace;
    background-color: var(--bg-color);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.footer {
    text-align: center;
    padding: 24px 24px 32px;
    color: var(--text-secondary-color);
    font-size: 0.9rem;
}

.support-link {
    color: inherit;
    font-weight: 600;
    text-decoration: none;
}

.support-link:hover {
    text-decoration: underline;
}
