/* Wikipedia Golf - Golf Course Design */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    color: #16301c;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans JP", Helvetica, Arial, sans-serif;
    background: linear-gradient(to bottom, #bde3ff, #e8f6ff 40%, #74c174 41%, #5ca85c 100%) no-repeat;
    min-height: 100vh;
    background-attachment: fixed;
}

/* CSS Variables */
:root {
    --sky-top: #bde3ff;
    --sky-bottom: #e8f6ff;
    --grass-light: #74c174;
    --grass-dark: #5ca85c;
    --green: #2f8f3a;
    --sand: #edd39b;
    --flag: #e53935;
    --ink: #16301c;
    --ui: #ffffffee;
    --ui-border: #d8e7d6;
    --accent: #2c7a7b;
}

/* Golf ball decoration */
.ball-bg {
    position: fixed;
    bottom: 12vh;
    left: 50%;
    transform: translateX(-50%);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #fff;
    box-shadow: inset -6px -8px 0 0 #d7dfd8, 0 6px 8px rgba(0,0,0,0.2);
    z-index: 0;
}

/* Layout */
.app {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
    gap: 12px;
    position: relative;
    z-index: 1;
}

header {
    backdrop-filter: saturate(120%) blur(4px);
    background: linear-gradient(rgba(255,255,255,0.8), rgba(255,255,255,0.69));
    border-bottom: 1px solid var(--ui-border);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px clamp(12px, 2vw, 24px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
}

.brand .title {
    font-size: clamp(18px, 3.2vw, 22px);
}

.header-ctrls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--ui-border);
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover:not(:disabled) {
    filter: brightness(0.96);
}

.btn.secondary {
    background: #f7fbf7;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 8px clamp(12px, 2vw, 24px) 24px;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 16px;
}

/* Top route panel */
.top-route {
    grid-column: 1 / -1;
}

/* Game container holds players and board side by side */
.game-container {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
}

@media (max-width: 1080px) {
    .game-container {
        grid-template-columns: 1fr;
    }
    .panel.players {
        order: 1;
    }
}

.panel {
    background: var(--ui);
    border: 1px solid var(--ui-border);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.panel .hd {
    padding: 12px 14px;
    font-weight: 700;
    border-bottom: 1px solid var(--ui-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel .bd {
    padding: 14px;
}

.muted {
    opacity: 0.7;
}

/* Players panel */
.players .list {
    display: grid;
    gap: 8px;
}

.player {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px dashed var(--ui-border);
    border-radius: 12px;
    background: #fff;
    transition: all 0.2s;
}

.player.current {
    background: #e3f2fd;
    border: 2px solid var(--accent);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(44, 122, 123, 0.2);
    transform: scale(1.02);
}

.player.current .player-name {
    color: var(--accent);
    font-size: 1.05em;
}

.pill {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef8f0;
    border: 1px solid var(--ui-border);
}

.pill.host {
    background: #fff3e0;
    border-color: #ffb74d;
    color: #e65100;
}

.pill.ready {
    background: #e8f5e8;
    border-color: #4caf50;
    color: #2e7d32;
}

.pill.wait {
    background: #f5f5f5;
    border-color: #bdbdbd;
    color: #757575;
}

/* Time settings */
.time-settings {
    margin-bottom: 12px;
}

.time-select {
    width: 100%;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--ui-border);
    background: #fff;
    font-size: 14px;
    margin-top: 4px;
}

/* Board */
.board {
    display: grid;
    grid-template-rows: auto auto auto 1fr auto;
    min-height: 520px;
}

.board .toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--ui-border);
    background: rgba(255,255,255,0.65);
    backdrop-filter: blur(4px);
}

.input {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input input {
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--ui-border);
    background: #fff;
    min-width: 180px;
}

.ad-slot {
    display: grid;
    place-items: center;
    border: 1px dashed var(--ui-border);
    background: #fff;
    border-radius: 12px;
    padding: 10px;
    font-weight: 700;
    opacity: 0.8;
}

.page {
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.article {
    background: #fff;
    border: 1px solid var(--ui-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    flex: 1;
    overflow-y: auto;
}

.article h1 {
    font-size: clamp(18px, 2.2vw, 24px);
    margin: 0 0 6px 0;
}

.article .meta {
    font-size: 12px;
    opacity: 0.7;
    margin-bottom: 10px;
}

.article .content {
    max-height: 36ch;
    overflow: auto;
    padding-right: 6px;
}

.board .footer {
    display: flex;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid var(--ui-border);
    align-items: center;
    justify-content: space-between;
}

/* Route panel */
.route .steps {
    display: grid;
    gap: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.route .step {
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--ui-border);
    border-radius: 12px;
    position: relative;
}

.route .step.current {
    background: #f0f8ff;
    border-color: var(--accent);
}

.route .step .step-number {
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    text-align: center;
    line-height: 24px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 8px;
}

.route .step .step-title {
    display: inline;
    font-weight: 600;
}

footer {
    padding: 14px clamp(12px, 2vw, 24px);
    color: #1c3b21;
}

.footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.legal {
    font-size: 12px;
    opacity: 0.8;
}

/* Modal styles */
.room-selection {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.room-selection.active {
    display: flex;
}

.room-card {
    background: rgba(255,255,255,0.95);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    max-width: 500px;
    width: 90%;
    backdrop-filter: blur(10px);
}

.room-card h2 {
    text-align: center;
    color: #2c5530;
    margin-bottom: 30px;
    font-size: 1.8em;
}

.join-form, .name-form {
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    border: 2px dashed #ddd;
}

.join-form input, .name-form input {
    width: 100%;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    margin-bottom: 15px;
    font-size: 1em;
}

.join-form input:focus, .name-form input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-buttons {
    display: flex;
    gap: 10px;
}

.timer-display {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    color: white;
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    margin: 16px;
    box-shadow: 0 10px 30px rgba(255, 107, 107, 0.3);
}

.timer-value {
    font-size: 3em;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* Game status bar */
.game-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin: 16px;
    background: rgba(255,255,255,0.9);
    border-radius: 12px;
    border: 1px solid var(--ui-border);
}

.status-item {
    text-align: center;
    flex: 1;
}

.status-value {
    font-weight: 700;
    font-size: 1.2em;
    color: #2c5530;
}

.status-label {
    font-size: 0.8em;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Wiki link styles */
.wiki-link {
    color: var(--accent) !important;
    cursor: pointer;
    text-decoration: underline;
    transition: all 0.2s ease;
}

.wiki-link:hover {
    background: #f0f8ff;
    padding: 2px 4px;
    border-radius: 4px;
    text-decoration: none;
}

/* Show/hide states */
.hidden { 
    display: none !important; 
}

.visible { 
    display: block; 
}

/* Responsive design */
@media (max-width: 768px) {
    .header-inner {
        flex-direction: column;
        gap: 15px;
    }
    
    .header-ctrls {
        justify-content: center;
    }
    
    .room-card {
        padding: 25px;
        margin: 20px;
    }
    
    .game-status {
        flex-direction: column;
        gap: 15px;
    }
    
    .timer-value {
        font-size: 2.5em;
    }
    
    .form-buttons {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .brand .title {
        font-size: 1.5em;
    }
    
    .room-card {
        padding: 20px;
    }
    
    .timer-value {
        font-size: 2em;
    }
    
    .status-value {
        font-size: 1em;
    }
    
    main {
        padding: 8px 12px 24px;
    }
}

/* Loading and animation states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Focus states for accessibility */
.btn:focus,
input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Success and error states */
.success-message {
    text-align: center;
    font-size: 2.5em;
    color: var(--green);
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
    margin: 50px 0;
    animation: bounce 1s ease-in-out;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 20px;
    border-radius: 10px;
    border: 2px solid #ef5350;
    text-align: center;
    margin: 20px 0;
}

/* Final results styling */
.final-results {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 30px;
    margin: 20px 0;
    text-align: center;
}

.final-results h2 {
    color: var(--green);
    font-size: 2em;
    margin-bottom: 30px;
}

.ranking-list {
    display: grid;
    gap: 12px;
    max-width: 700px;
    margin: 0 auto;
}

.ranking-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.2s;
}

.ranking-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.ranking-item.winner {
    background: linear-gradient(135deg, #ffd700, #ffed4a);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.3);
}

.ranking-item.second {
    background: linear-gradient(135deg, #c0c0c0, #e6e6e6);
}

.ranking-item.third {
    background: linear-gradient(135deg, #cd7f32, #deb887);
}

.ranking-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 12px;
}

.player-rank {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.1em;
}

.medal {
    font-size: 1.5em;
    width: 30px;
    text-align: center;
}

.player-score {
    font-weight: 700;
    color: #2c5530;
    font-size: 1.1em;
}

.player-route {
    width: 100%;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.route-title {
    font-weight: 600;
    color: #666;
    font-size: 0.9em;
    margin-bottom: 8px;
}

.route-path {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.route-page {
    background: #f5f5f5;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.85em;
    color: #333;
    border: 1px solid #ddd;
}

.route-page.start {
    background: #e3f2fd;
    border-color: #2196f3;
    color: #1976d2;
}

.route-page.goal {
    background: #e8f5e8;
    border-color: #4caf50;
    color: #2e7d32;
}

.route-arrow {
    color: #999;
    font-size: 0.8em;
    margin: 0 2px;
}

.timeout-message {
    color: #f57c00;
    font-style: italic;
    opacity: 0.8;
}

/* Scroll to top after link navigation */
html {
    scroll-behavior: smooth;
}

/* Personal result and waiting message styles */
.personal-result, .waiting-message {
    text-align: center;
    padding: 50px 20px;
    background: #f0f8ff;
    border-radius: 15px;
    margin: 20px 0;
}

.personal-result h3, .waiting-message h3 {
    color: var(--green);
    font-size: 2em;
    margin-bottom: 15px;
}

.personal-result p, .waiting-message p {
    font-size: 1.2em;
    color: #666;
    margin: 0;
}

/* Completion status styles */
.completion-status {
    background: #fff;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--ui-border);
}

.status-header {
    font-weight: 700;
    margin-bottom: 12px;
    color: #2c5530;
    text-align: center;
}

.completion-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}

.completion-item.completed {
    background: #e8f5e8;
    border-color: #4caf50;
}

.completion-item.waiting {
    background: #fff3e0;
    border-color: #ff9800;
}