:root {
    --bg-color: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --board-bg: #fcd34d; /* Warm wood-like color */
    --board-line: #b45309;
    --piece-bg: #fffbeb;
    --piece-text: #1e293b;
    --piece-text-promoted: #dc2626;
    --highlight-valid: rgba(239, 68, 68, 0.6);
    --highlight-selected: rgba(59, 130, 246, 0.5);
    --highlight-lastmove: rgba(16, 185, 129, 0.4);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Inter', 'Noto Serif JP', sans-serif;
    background: var(--bg-color);
    background-image: radial-gradient(circle at 50% 0%, #1e293b 0%, #0f172a 100%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 1000px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

h1 {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(to right, #fcd34d, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

select {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    background: rgba(15, 23, 42, 0.8);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    font-family: 'Inter', sans-serif;
    outline: none;
    cursor: pointer;
    transition: border-color 0.3s;
}

select:focus {
    border-color: #3b82f6;
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Inter', sans-serif;
}

.btn.primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

.btn.secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

.status-message {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 1rem 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 100;
    transition: all 0.3s;
}

.game-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    position: relative;
}

/* Hands */
.hand-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 140px;
}

.hand-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
}

.hand {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    min-height: 400px;
    padding: 1rem;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 5px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

/* Board */
.board-wrapper {
    padding: 1.5rem;
    background: var(--glass-bg);
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
}

.board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    background-color: var(--board-bg);
    border: 2px solid var(--board-line);
    width: min(80vw, 540px);
    height: min(80vw, 540px);
    position: relative;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
}

.square {
    border: 1px solid var(--board-line);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

/* 3x3 dots */
.square::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--board-line);
    border-radius: 50%;
    display: none;
}
.square[data-row="2"][data-col="2"]::after,
.square[data-row="2"][data-col="5"]::after,
.square[data-row="2"][data-col="8"]::after,
.square[data-row="5"][data-col="2"]::after,
.square[data-row="5"][data-col="5"]::after,
.square[data-row="5"][data-col="8"]::after,
.square[data-row="8"][data-col="2"]::after,
.square[data-row="8"][data-col="5"]::after,
.square[data-row="8"][data-col="8"]::after {
    display: block;
    top: -4px;
    left: -4px;
    z-index: 1;
}

/* Pieces */
.piece {
    width: 80%;
    height: 90%;
    background: linear-gradient(to bottom, #fffbeb, #fef3c7);
    color: var(--piece-text);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: 'Noto Serif JP', serif;
    font-size: clamp(1rem, 3.5vw, 1.8rem);
    font-weight: 700;
    cursor: grab;
    position: absolute;
    box-shadow: 1px 2px 4px rgba(0,0,0,0.4), inset 1px 1px 2px rgba(255,255,255,0.8);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
    user-select: none;
    clip-path: polygon(50% 0%, 100% 25%, 90% 100%, 10% 100%, 0% 25%);
    z-index: 10;
}

.piece.gote {
    transform: rotate(180deg);
}
.piece.gote.selected {
    transform: rotate(180deg) scale(1.1) translateY(-5px);
}
.piece.selected {
    transform: scale(1.1) translateY(-5px);
    box-shadow: 2px 5px 10px rgba(0,0,0,0.5), inset 1px 1px 2px rgba(255,255,255,0.8);
    z-index: 20;
}

.piece.promoted {
    color: var(--piece-text-promoted);
}

.hand .piece {
    position: relative;
    width: 45px;
    height: 52px;
    font-size: 1.2rem;
    transform: none;
}
.hand .piece.gote {
    transform: none; /* In hand, pieces face the player who owns them normally */
}

/* Highlights */
.square.selected {
    background-color: var(--highlight-selected);
}

.square.valid-move {
    background-color: var(--highlight-valid);
    /* Make it look like a red frame as requested */
    box-shadow: inset 0 0 0 3px #ef4444; 
}

.square.valid-move:hover {
    background-color: rgba(239, 68, 68, 0.8);
}

.square.last-move {
    background-color: var(--highlight-lastmove);
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--glass-bg);
    padding: 2rem 3rem;
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    text-align: center;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.hidden .modal-content {
    transform: translateY(20px);
}

.modal-content p {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    font-weight: 600;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.analysis-content {
    max-width: 600px;
    width: 90%;
    text-align: left;
}

.analysis-content h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #fcd34d;
}

.analysis-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.5rem;
    border-left: 4px solid #3b82f6;
}

.analysis-section h3 {
    margin-bottom: 0.5rem;
    color: #94a3b8;
    font-size: 1.1rem;
}

.highlight-text {
    color: #ef4444;
    font-weight: bold;
}

button.hidden {
    display: none;
}

@media (max-width: 800px) {
    .game-container {
        flex-direction: column;
    }
    .hand-container {
        width: min(80vw, 540px);
        flex-direction: row;
        align-items: center;
    }
    .hand {
        flex-direction: row;
        min-height: 80px;
        width: 100%;
    }
}

/* Oute Text */
.oute-text {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 8rem;
    font-weight: 900;
    color: #ef4444;
    text-shadow: 0 0 20px rgba(0,0,0,0.8), 2px 2px 0 #fff, -2px -2px 0 #fff, 2px -2px 0 #fff, -2px 2px 0 #fff;
    pointer-events: none;
    z-index: 10000;
    animation: outeAnim 2s forwards;
    opacity: 0;
}

@keyframes outeAnim {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    20% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    30% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.1); opacity: 0; }
}
