:root {
    --font-main: 'Sawarabi Gothic', sans-serif;
    --font-mono: 'Roboto Mono', monospace;

    /* Blue High-Contrast Theme */
    --bg-color: #e3f2fd;
    --bg-gradient: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);

    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(25, 118, 210, 0.3);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);

    --text-main: #0d47a1;
    /* Deep Blue */
    --text-sub: #1565c0;

    --accent-color: #1976d2;
    --accent-glow: rgba(25, 118, 210, 0.3);

    --card-hidden-bg: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    --card-hidden-text: #ffffff;

    --card-revealed-bg: #ffffff;
    --card-revealed-text-color: #0d47a1;

    --strike-color: #c62828;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    background-image: var(--bg-gradient);
    color: var(--text-main);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    max-width: 1280px;
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--glass-shadow);
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 40px;
    height: 110px;
}

.topic-box {
    display: flex;
    flex-direction: column;
}

.label {
    font-size: 0.9rem;
    color: var(--text-sub);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 700;
}

#topic-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--text-main);
    outline: none;
    border-bottom: 2px solid transparent;
    text-shadow: 2px 2px 0px rgba(255, 255, 255, 0.5);
}

#topic-title:focus {
    border-color: var(--accent-color);
}

.remaining-box {
    text-align: right;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.remaining-box .count {
    font-family: var(--font-mono);
    font-size: 4rem;
    font-weight: 900;
    color: var(--accent-color);
    /* text-shadow: 0 0 10px var(--accent-glow); */
}

.remaining-box .unit {
    font-size: 1.5rem;
    color: var(--text-sub);
    font-weight: 700;
}

/* Main Grid (Ranking List) */
/* Rank Item Container */
.rank-item {
    display: flex;
    align-items: stretch;
    /* Stretch height */
    width: calc(50% - 20px);
    height: 60px;
    margin-bottom: 0;
    filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.15));
    /* Shadow on the whole shape */
    transition: transform 0.2s;
}

.rank-item:hover {
    transform: translateY(-2px);
    filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.2));
}

/* Rank Number styling (Left Pill Half) */
.rank-num {
    font-family: var(--font-mono);
    font-weight: 900;
    color: #1976d2;
    /* Blue text */
    width: 70px;
    height: 100%;
    background: #fff;
    /* White bg */
    border: 4px solid #1976d2;
    /* Connect */
    border-radius: 8px 0 0 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-right: 0;
    text-shadow: none;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    font-size: 3.2rem;
    /* Large font to fill height */
    line-height: 1;
    padding-right: 2px;
    padding-bottom: 4px;
    /* Optical centering */
}

/* Add '位' suffix conditionally */
.grid-container.show-suffix .rank-num::after {
    content: '位';
    font-size: 1.0rem;
    margin-top: 8px;
    /* Align baseline roughly */
    margin-left: 2px;
    font-weight: 700;
    opacity: 0.9;
}

/* Rank Panel (Right Pill Half) */
.rank-panel {
    flex: 1;
    height: 100%;
    background: #fff;
    color: var(--card-hidden-text);
    border-radius: 0 30px 30px 0;
    /* Rounded Right */
    border: 4px solid #1976d2;
    /* Match rank color */
    border-left: none;
    /* Merge look */
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 20px;
    position: relative;
    transition: all 0.3s;
    overflow: hidden;
    box-shadow: none;
    /* Handled by container filter */
}

/* Hidden state decorative pattern */
.rank-panel::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(45deg, #e3f2fd 25%, transparent 25%, transparent 50%, #e3f2fd 50%, #e3f2fd 75%, transparent 75%, transparent);
    background-size: 20px 20px;
    opacity: 0.6;
}

/* Revealed State */
.rank-panel.revealed {
    background: #fff;
    color: #1976d2;
    /* Text color matches border */
    transform: none;
    font-size: 1.6rem;
    font-weight: 700;
    justify-content: center;
    /* Center text */
    box-shadow: none;
}

.rank-panel.revealed::after {
    display: none;
}

.rank-panel.hinted {
    color: #0d47a1;
    /* Visible text color */
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 2px;
}

.admin-link {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.4);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    text-decoration: none;
    font-size: 1.5rem;
    color: var(--text-sub);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0.3;
    transition: all 0.2s;
    z-index: 1000;
    border: 2px solid transparent;
}

.admin-link:hover {
    opacity: 1;
    background: #fff;
    border-color: var(--accent-color);
}

.main-area {
    flex: 1;
    padding: 24px 40px;
    overflow: hidden;
    /* Hide scroll */
    display: block;
    /* Block for flex container inside */
    position: relative;
}

.grid-container {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-content: flex-start;
    /* columns start from left */
    gap: 12px 40px;
    /* Row gap 12px, Column gap 40px */
    height: 100%;
    width: 100%;
}

.rank-item {
    display: flex;
    align-items: center;
    /* Adjust width based on how many columns we expect. 
     If we want auto columns, give it a max-width or fixed width.
     With flex-direction: column + wrap, items need a width.
     Let's try calc(50% - 20px) for 2 columns safely. */
    width: calc(50% - 20px);
    height: 60px;
    /* Fixed height is important for column wrapping calculation */
}

.rank-num {
    font-family: var(--font-mono);
    font-size: 1.8rem;
    font-weight: 900;
    color: #fff;
    width: 50px;
    text-align: right;
    margin-right: 15px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    color: var(--text-sub);
}

.rank-panel {
    flex: 1;
    height: 100%;
    background: var(--card-hidden-bg);
    color: var(--card-hidden-text);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* Start hidden state blank or pattern? */
    padding: 0 20px;
    box-shadow: 0 4px 0px #1565c0, 0 5px 5px rgba(0, 0, 0, 0.1);
    position: relative;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    overflow: hidden;
}

/* Hidden state decorative pattern or text? */
.rank-panel::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(45deg, rgba(255, 255, 255, 0.1) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.1) 75%, transparent 75%, transparent);
    background-size: 20px 20px;
    opacity: 0.3;
}

/* Revealed State */
.rank-panel.revealed {
    background: var(--card-revealed-bg);
    color: var(--card-revealed-text-color);
    transform: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    border: 4px solid var(--accent-color);
    font-size: 1.6rem;
    font-weight: 700;
    justify-content: center;
    /* Center text */
}

.rank-panel.revealed::after {
    display: none;
}

/* Footer (Participants) */
.footer {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    height: 150px;
}

.participant {
    padding: 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.6);
    /* Lighter footer */
    position: relative;
}

.icon-placeholder {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    /* Circle icon */
    background: #fff;
    border: 4px solid var(--accent-color);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--accent-color);
    font-size: 2.5rem;
    flex-shrink: 0;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.participant-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.participant .name {
    font-size: 1.2rem;
    font-weight: 800;
    margin-bottom: 5px;
    color: var(--text-main);
    border-bottom: 2px solid transparent;
}

.participant .name:focus {
    border-color: var(--accent-color);
}

.score-area {
    display: flex;
    align-items: baseline;
    gap: 5px;
    margin-bottom: 5px;
}

.score-value {
    font-family: var(--font-mono);
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--text-main);
    line-height: 1;
}

.score-label {
    font-size: 1rem;
    color: var(--text-sub);
    font-weight: 700;
}

.strikes {
    color: var(--strike-color);
    font-size: 2rem;
    font-weight: 900;
    height: 30px;
    display: flex;
    gap: 5px;
    line-height: 1;
    margin-top: 5px;
}

/* Controls (hidden by default unless hovered) */
.controls {
    position: absolute;
    top: -15px;
    right: 10px;
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.3s;
    background: #fff;
    padding: 5px 10px;
    border-radius: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.participant:hover .controls {
    opacity: 1;
    top: -20px;
}

.controls button {
    background: #e3f2fd;
    color: var(--accent-color);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.1rem;
    border: none;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.controls button:hover {
    background: var(--accent-color);
    color: white;
}

.controls button.btn-strike {
    color: var(--strike-color);
    background: #ffebee;
}

.controls button.btn-strike:hover {
    background: var(--strike-color);
    color: white;
}

/* Admin Button */
.admin-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    opacity: 0.3;
    transition: opacity 0.3s;
    z-index: 100;
}

.admin-btn:hover {
    opacity: 1;
    background: #fff;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(13, 71, 161, 0.4);
    /* Blue tinted dim */
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: white;
    width: 500px;
    max-width: 90%;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 16px;
    border: 4px solid var(--accent-color);
    background: #fafafa;
}

.modal h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.modal textarea {
    width: 100%;
    height: 300px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 1rem;
    resize: vertical;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 700;
    transition: 0.2s;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    background: #cfd8dc;
    color: #546e7a;
}

.btn-secondary:hover {
    background: #bdc3c7;
}