/* =========================================
   1. ベース設定 & 背景アニメーション
   ========================================= */
body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    margin: 0; padding: 0; min-height: 100vh; overflow-x: hidden;
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%; animation: gradientBG 15s ease infinite; color: #444;
}
@keyframes gradientBG {
    0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; }
}
.app-wrapper { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 20px 20px 60px 20px; box-sizing: border-box; }
.container {
    background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    width: 100%; max-width: 500px; padding: 30px; border-radius: 24px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2); border: 1px solid rgba(255, 255, 255, 0.4);
    position: relative; z-index: 10; display: none; animation: fadeIn 0.4s ease;
}
#view-home { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
.fixed-footer { position: fixed; bottom: 10px; width: 100%; text-align: center; z-index: 5; pointer-events: none; }
.footer-text { font-family: 'Poppins', sans-serif; font-size: 10px; color: rgba(255, 255, 255, 0.7); letter-spacing: 0.05em; text-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* =========================================
   2. メニュー
   ========================================= */
.menu-btn {
    position: fixed; top: 20px; left: 20px; z-index: 100;
    background: rgba(255,255,255,0.9); border: none; border-radius: 12px;
    width: 45px; height: 45px; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px;
    transition: transform 0.1s; -webkit-tap-highlight-color: transparent;
}
.menu-btn:active { transform: scale(0.9); background: #eee; }
.menu-line { width: 24px; height: 3px; background: #7b1fa2; border-radius: 2px; transition: 0.3s; }
.side-drawer {
    position: fixed; top: 0; left: -280px; width: 280px; height: 100vh;
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(15px); box-shadow: 5px 0 25px rgba(0,0,0,0.1);
    z-index: 99; transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column; padding-top: 80px;
}
.side-drawer.open { left: 0; }
.menu-item {
    padding: 15px 30px; font-size: 16px; font-weight: bold; color: #555; cursor: pointer;
    transition: 0.2s; display: flex; align-items: center; gap: 15px; font-family: 'Poppins', sans-serif;
    -webkit-tap-highlight-color: transparent;
}
.menu-item:hover { background: #f3e5f5; color: #7b1fa2; }
.menu-item.active { border-right: 4px solid #7b1fa2; background: #f3e5f5; color: #7b1fa2; }
.menu-icon { font-size: 20px; width: 24px; text-align: center; }
.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.3);
    z-index: 98; opacity: 0; visibility: hidden; transition: 0.3s;
}
.overlay.open { opacity: 1; visibility: visible; }

/* =========================================
   3. UI共通パーツ
   ========================================= */
.header { text-align: center; margin-bottom: 30px; }
.brand-badge {
    display: inline-block; background: #e1bee7; color: #7b1fa2; padding: 4px 12px;
    border-radius: 20px; font-size: 11px; font-weight: bold; letter-spacing: 0.1em;
    margin-bottom: 5px; font-family: 'Poppins', sans-serif;
}
h2 { margin: 0; color: #4a148c; font-size: 26px; font-family: 'Poppins', sans-serif; letter-spacing: 0.05em; }
p { font-size: 14px; color: #555; margin-bottom: 8px; line-height: 1.6; }
textarea {
    width: 100%; height: 100px; font-size: 16px; padding: 16px; box-sizing: border-box;
    margin-bottom: 25px; border: 2px solid transparent; border-radius: 16px;
    background: rgba(255, 255, 255, 0.9); box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
    transition: all 0.3s; font-family: inherit; resize: none;
}
textarea:focus { outline: none; border-color: #ba68c8; background: white; box-shadow: 0 0 0 4px rgba(186, 104, 200, 0.25); }
.option-box {
    margin-bottom: 35px; padding: 15px 20px; background: rgba(255,255,255,0.6);
    border-radius: 16px; display: flex; justify-content: space-between; align-items: center;
    border: 1px solid rgba(255,255,255,0.8);
}
.toggle-label { font-weight: bold; color: #4a148c; display: flex; flex-direction: column; }
.toggle-desc { font-size: 11px; font-weight: normal; color: #777; margin-top: 4px; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 34px;
}
.slider:before {
    position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px;
    background-color: white; transition: .4s; border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background: linear-gradient(135deg, #ba68c8, #7b1fa2); }
input:checked + .slider:before { transform: translateX(22px); }

button.run-btn {
    width: 100%; padding: 18px; font-size: 16px; background: linear-gradient(135deg, #ab47bc, #7b1fa2);
    color: white; border: none; border-radius: 50px; font-weight: bold;
    font-family: 'Poppins', sans-serif; letter-spacing: 0.05em; cursor: pointer;
    transition: all 0.1s; box-shadow: 0 6px 0 #7b1fa2, 0 10px 10px rgba(0,0,0,0.2);
    position: relative; overflow: hidden; -webkit-tap-highlight-color: transparent; margin-bottom: 6px;
}
button.run-btn:hover { transform: translateY(-3px) scale(1.02); }
button.run-btn:active { transform: translateY(6px); box-shadow: 0 0 0 #7b1fa2, inset 0 0 10px rgba(0,0,0,0.3); filter: brightness(0.9); }

#result-area { display: none; margin-top: 30px; animation: slideUp 0.5s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
#result { padding: 15px; border-top: 2px dashed rgba(0,0,0,0.1); line-height: 1.8; font-size: 15px; margin-bottom: 20px; }

.copy-btn {
    width: 100%; padding: 14px; font-size: 14px; background: rgba(255, 255, 255, 0.6);
    color: #7b1fa2; border: 2px solid #7b1fa2; border-radius: 12px; font-weight: bold;
    font-family: 'Poppins', sans-serif; cursor: pointer; transition: all 0.1s;
    display: flex; justify-content: center; align-items: center; gap: 8px; -webkit-tap-highlight-color: transparent;
}
.copy-btn:active { transform: scale(0.95); background: #e1bee7; }
.copy-btn.copied { background: #4caf50; border-color: #4caf50; color: white; pointer-events: none; }

/* =========================================
   4. 各機能
   ========================================= */
.timer-display {
    font-family: 'Roboto Mono', monospace; font-size: 64px; font-weight: bold;
    color: #4a148c; text-align: center; margin: 30px 0; text-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.timer-controls { display: flex; gap: 20px; justify-content: center; margin-bottom: 30px; }
.control-btn {
    width: 80px; height: 80px; border-radius: 50%; border: none; font-size: 32px;
    cursor: pointer; display: flex; justify-content: center; align-items: center;
    box-shadow: 0 6px 0 rgba(0,0,0,0.2); transition: 0.1s;
}
.control-btn:active { transform: translateY(6px); box-shadow: none; }
.btn-start { background: #66bb6a; color: white; border-bottom: 4px solid #388e3c; }
.btn-stop { background: #ef5350; color: white; border-bottom: 4px solid #d32f2f; }
.btn-reset { background: #f5f5f5; color: #555; border-bottom: 4px solid #bdbdbd; }
.timer-presets { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.preset-chip {
    padding: 8px 16px; background: rgba(255,255,255,0.6); border: 1px solid #ba68c8;
    border-radius: 20px; color: #7b1fa2; font-weight: bold; cursor: pointer;
}
.history-list { list-style: none; padding: 0; max-height: 400px; overflow-y: auto; }
.history-item { background: white; border-radius: 16px; margin-bottom: 15px; padding: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.inv-display { text-align: center; margin: 20px 0; }
.inv-count { font-size: 72px; font-weight: bold; color: #e65100; font-family: 'Roboto Mono', monospace; }
.inv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 30px; }
.inv-btn {
    padding: 15px; border-radius: 16px; border: none; font-weight: bold; font-size: 16px;
    cursor: pointer; display: flex; flex-direction: column; align-items: center;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}
.inv-btn:active { transform: translateY(4px); box-shadow: none; }
.btn-use { background: #ffebee; color: #c62828; }
.btn-add { background: #e8f5e9; color: #2e7d32; }
#loading-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.9); z-index: 999;
    flex-direction: column; justify-content: center; align-items: center;
}
.fox-row { display: flex; gap: 20px; }
.fox-emoji { font-size: 50px; animation: bounce 0.5s infinite alternate; }
@keyframes bounce { to { transform: translateY(-20px); } }

/* =========================================
   5. スタンダードトーナメント表 (左→右)
   ========================================= */
.standard-bracket { display: flex; flex-direction: row; padding: 20px; gap: 0; }
.round-column {
    display: flex; flex-direction: column; justify-content: space-around;
    width: 160px; flex-shrink: 0; position: relative; margin-right: 40px;
}
.round-column:last-child { margin-right: 0; }
.match-pair {
    display: flex; flex-direction: column; justify-content: center;
    position: relative; margin: 10px 0;
}
.match {
    background: white; border: 1px solid #ccc; border-radius: 6px; padding: 5px 8px;
    margin: 8px 0; box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    position: relative; z-index: 2; height: 40px;
    display: flex; flex-direction: column; justify-content: center;
}
.team {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 11px; cursor: pointer; border-radius: 4px; padding: 2px 4px;
}
.team:hover { background: #f0f0f0; }
.team.winner { background: #e1bee7; color: #7b1fa2; font-weight: bold; }
.team-score { font-family: 'Roboto Mono', monospace; color: #555; margin-left: 6px; }

/* 線の描画 */
:root { --line-color: #aaa; --line-width: 2px; }
.match-pair::after {
    content: ''; position: absolute; right: -22px; top: 50%;
    width: 22px; height: var(--line-width); background: var(--line-color); z-index: 1;
}
.round-column:last-child .match-pair::after { display: none; }
.match-pair::before {
    content: ''; position: absolute; right: -22px; top: 50%; height: 100%; width: 1px;
}
.connector-top {
    position: absolute; right: -22px; top: 25%; width: 22px; height: 50%;
    border-right: var(--line-width) solid var(--line-color);
    border-top: var(--line-width) solid var(--line-color); pointer-events: none;
}
.connector-single {
    position: absolute; right: -22px; top: 50%; width: 22px; height: var(--line-width);
    background: var(--line-color);
}

/* =========================================
   6. リーグ戦テーブル & モーダル
   ========================================= */
.league-table {
    width: 100%; border-collapse: collapse; background: white; border-radius: 12px;
    overflow: hidden; box-shadow: 0 4px 10px rgba(0,0,0,0.05); table-layout: fixed;
}
.league-table th, .league-table td {
    border: 1px solid #eee; padding: 8px 4px; text-align: center;
    font-size: 12px; word-break: break-all;
}
.league-table th { background: #7b1fa2; color: white; font-weight: bold; }
.league-cell {
    cursor: pointer; user-select: none; font-weight: bold; color: #ddd; height: 32px;
    display: flex; align-items: center; justify-content: center;
    flex-direction: column; line-height: 1;
}
.cell-score { font-size: 10px; color: #555; font-family: 'Roboto Mono'; margin-top: 2px; }
.cell-win { color: #e91e63; font-size: 14px; }
.cell-lose { color: #3f51b5; font-size: 14px; }
.cell-draw { background: #f5f5f5; }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: none; justify-content: center; align-items: center; backdrop-filter: blur(4px);
}
.modal-box {
    background: white; width: 85%; max-width: 320px; padding: 25px;
    border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); text-align: center;
}
.modal-title { font-weight: bold; color: #4a148c; margin-bottom: 15px; font-size: 18px; }
.modal-input {
    padding: 10px; font-size: 20px; text-align: center;
    border: 2px solid #eee; border-radius: 10px; outline: none;
}
.modal-input:focus { border-color: #ba68c8; }
.modal-btns { display: flex; gap: 10px; margin-top: 20px; }
.modal-btn {
    flex: 1; padding: 12px; border: none; border-radius: 50px;
    font-weight: bold; cursor: pointer;
}
.btn-cancel { background: #f5f5f5; color: #777; }
.btn-ok { background: #7b1fa2; color: white; }