* { 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; }
.hidden { display: none !important; }

.settings-container {
    max-width: 560px; margin: auto; padding: 40px;
    background: rgba(0,0,0,0.3); border-radius: 20px; text-align: center;
}
.settings-container h1 { font-size: 3rem; margin-bottom: 10px; }
.settings-container h2 { font-size: 2rem; margin-bottom: 30px; font-weight: normal; opacity: 0.9; }
.setting-group { margin-bottom: 24px; }
.setting-group label { display: block; font-size: 1.3rem; margin-bottom: 10px; }
.player-input {
    width: 100%; padding: 14px 18px; font-size: 1.3rem;
    border: 3px solid #fff; border-radius: 10px;
    background: rgba(255,255,255,0.9); color: #2c3e50; text-align: center; display: block;
}
.player-input:focus { outline: 4px solid #f39c12; outline-offset: 2px; }
.button-group { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.setting-btn {
    padding: 12px 18px; font-size: 1.05rem;
    border: 3px solid #fff; background: transparent; color: #fff;
    border-radius: 12px; cursor: pointer; transition: all 0.2s;
    min-width: 130px; min-height: 56px;
}
.setting-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.05); }
.setting-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }
.setting-btn.active { background: #fff; color: #2c3e50; font-weight: bold; }
.primary-btn {
    margin-top: 18px; padding: 18px 40px; font-size: 1.7rem;
    background: #e74c3c; color: #fff; border: none; border-radius: 15px;
    cursor: pointer; font-weight: bold; transition: all 0.2s;
    min-height: 70px; display: flex; width: 100%; align-items: center; justify-content: center;
    text-decoration: none;
}
.primary-btn:hover { background: #c0392b; transform: scale(1.03); }
.primary-btn:focus { outline: 4px solid #f39c12; outline-offset: 3px; }
.secondary-btn { margin-top: 12px; background: rgba(255,255,255,0.2); border: 3px solid #fff; }
.secondary-btn:hover { background: rgba(255,255,255,0.35); }
.back-btn { text-decoration: none; }

.rules-summary {
    background: rgba(255,255,255,0.1); border-radius: 12px;
    padding: 18px 22px; margin: 20px 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; }

/* Header */
.game-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 20px; background: rgba(0,0,0,0.3);
    flex-wrap: wrap; gap: 10px; min-height: 80px;
}
.game-header h1 { font-size: 1.8rem; }
.turn-display {
    font-size: 1.4rem; font-weight: bold; padding: 10px 20px;
    border-radius: 10px; background: rgba(255,255,255,0.15);
}
.action-btn {
    padding: 12px 18px; font-size: 1.05rem;
    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: 48px;
    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; }

/* Game Area */
.game-area {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; padding: 12px; gap: 10px; overflow: auto;
}

/* Captures / Hand */
.captures-area {
    display: flex; align-items: center; gap: 10px; width: 100%; max-width: 700px;
    background: rgba(0,0,0,0.2); border-radius: 10px; padding: 8px 14px; min-height: 60px;
}
.captures-label { font-size: 1rem; opacity: 0.7; flex-shrink: 0; }
.hand { display: flex; flex-wrap: wrap; gap: 6px; }
.hand-piece {
    width: 52px; height: 58px;
    background: transparent; border: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.15s; position: relative;
}
.hand-piece-inner {
    width: 44px; height: 50px;
    clip-path: polygon(50% 4%, 97% 24%, 97% 97%, 3% 97%, 3% 24%);
    background: linear-gradient(175deg, #fff8e8 0%, #e8c878 45%, #c89040 100%);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding-top: 10%; font-weight: bold; text-align: center; color: #2a1200;
    filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.45));
    transition: all 0.15s;
}
.hand-piece:hover .hand-piece-inner { filter: drop-shadow(0 0 6px rgba(243,156,18,0.9)) drop-shadow(1px 2px 3px rgba(0,0,0,0.4)); transform: scale(1.1); }
.hand-piece:focus { outline: none; }
.hand-piece:focus .hand-piece-inner { filter: drop-shadow(0 0 6px #f39c12) drop-shadow(1px 2px 3px rgba(0,0,0,0.4)); }
.hand-piece.selected .hand-piece-inner { filter: drop-shadow(0 0 8px rgba(243,156,18,1)) drop-shadow(1px 2px 3px rgba(0,0,0,0.4)); transform: scale(1.1); }
.hand-kanji { font-size: 1.1rem; line-height: 1; }
.hand-count { font-size: 0.6rem; font-weight: bold; opacity: 0.75; margin-top: 1px; }

/* Board */
.shogi-board {
    display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px;
    background: #6b4e10; padding: 2px; border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5); width: 100%; max-width: 700px;
}

/* Cells */
.board-cell {
    aspect-ratio: 1 / 1.1; background: #c8a870;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; position: relative; transition: background 0.15s; border-radius: 1px;
}
.board-cell:hover { background: #dbbe8a; }
.board-cell:focus { outline: 3px solid #f39c12; outline-offset: -3px; }
.board-cell.selected { background: #ffe04a; }
.board-cell.valid-move { background: rgba(144, 238, 144, 0.8); cursor: pointer; }
.board-cell.valid-move:hover { background: rgba(100, 200, 100, 0.9); }

/* Pieces - Traditional pentagonal Shogi shape */
.piece {
    width: 90%; height: 94%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    clip-path: polygon(50% 4%, 97% 24%, 97% 97%, 3% 97%, 3% 24%);
    background: linear-gradient(175deg, #fff8e8 0%, #e8c878 45%, #c89040 100%);
    color: #2a1200;
    font-weight: bold; text-align: center;
    pointer-events: none;
    filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.5));
    padding-top: 10%;
}
.piece.gote { transform: rotate(180deg); }
.piece.promoted .piece-kanji { color: #c0392b; }
.piece-kanji { font-size: clamp(1.1rem, 4vw, 2rem); line-height: 1; }
.piece-name  { font-size: clamp(0.22rem, 0.85vw, 0.42rem); opacity: 0.5; margin-top: 1px; }

/* Promotion Dialog */
.promo-dialog {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.promo-dialog.hidden { display: none; }
.promo-inner {
    background: #2c3e50; border: 3px solid #f39c12; border-radius: 20px;
    padding: 40px; text-align: center; max-width: 400px;
}
.promo-inner p { font-size: 1.6rem; margin-bottom: 24px; }
.promo-buttons { display: flex; gap: 16px; justify-content: center; }
.promo-btn {
    padding: 16px 28px; font-size: 1.3rem; font-weight: bold;
    border: none; border-radius: 12px; cursor: pointer; transition: all 0.2s; min-height: 60px;
}
.promo-btn.yes { background: #27ae60; color: #fff; }
.promo-btn.yes:hover { background: #1e8449; transform: scale(1.05); }
.promo-btn.no  { background: #7f8c8d; color: #fff; }
.promo-btn.no:hover { background: #636e72; transform: scale(1.05); }
.promo-btn:focus { outline: 4px solid #f39c12; outline-offset: 2px; }

/* End Screen */
.result-container {
    max-width: 500px; margin: auto; padding: 50px 40px;
    background: rgba(0,0,0,0.4); border-radius: 20px; text-align: center;
}
.result-container h1 { font-size: 3rem; margin-bottom: 20px; }
.result-container p { font-size: 1.5rem; margin-bottom: 15px; opacity: 0.9; }

@media (max-width: 768px) {
    .game-header { justify-content: center; }
    .header-left { display: none; }
    .header-center, .header-right { width: 100%; justify-content: center; }
}
