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

:root {
  --primary: #5C6BC0;
  --primary-dark: #3949AB;
  --daikichi: #2E7D32;
  --chukichi: #4CAF50;
  --kichi: #81C784;
  --kyou: #F44336;
  --daikyou: #B71C1C;
  --neutral: #9E9E9E;
  --bg: #f5f5f5;
  --card: #fff;
  --text: #212121;
  --text-light: #757575;
  --border: #e0e0e0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 18px; font-weight: 600; }
.btn-icon {
  background: none; border: none; color: #fff; font-size: 22px; cursor: pointer;
  padding: 4px 8px; border-radius: 4px;
}
.btn-icon:hover { background: rgba(255,255,255,.15); }

/* Layout */
.container {
  display: flex;
  height: calc(100vh - 52px);
}

.sidebar {
  width: 360px;
  min-width: 360px;
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--card);
}

.main {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  background: #e8e8e8;
  color: var(--text-light);
  font-size: 14px;
  line-height: calc(100vh - 52px);
  text-align: center;
}

/* Date controls */
.date-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.date-controls input[type="date"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

/* User info */
.user-info { margin-bottom: 16px; }
.user-stars {
  display: flex;
  gap: 16px;
  font-size: 14px;
}
.user-stars strong { color: var(--primary); }
.hint { color: var(--text-light); font-size: 13px; }

/* Ban grids */
.ban-section {
  margin-bottom: 12px;
}
.ban-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.ban-center {
  font-weight: 400;
  color: var(--text-light);
  font-size: 12px;
}
.ban-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  margin-bottom: 8px;
}
.ban-cell {
  text-align: center;
  padding: 6px 4px;
  border-radius: 4px;
  background: #f9f9f9;
  border: 1px solid var(--border);
}
.ban-cell.center-cell { background: #FFF9C4; }
.cell-dir { display: block; font-size: 10px; color: var(--text-light); }
.cell-star { display: block; font-size: 13px; font-weight: 600; }

/* Star colors */
.star-1 .cell-star { color: #fff; background: #2196F3; border-radius: 3px; }
.star-2 .cell-star { color: #fff; background: #795548; border-radius: 3px; }
.star-3 .cell-star { color: #fff; background: #4CAF50; border-radius: 3px; }
.star-4 .cell-star { color: #fff; background: #66BB6A; border-radius: 3px; }
.star-5 .cell-star { color: #fff; background: #FFC107; border-radius: 3px; color: #333; }
.star-6 .cell-star { color: #fff; background: #9E9E9E; border-radius: 3px; }
.star-7 .cell-star { color: #fff; background: #F44336; border-radius: 3px; }
.star-8 .cell-star { color: #fff; background: #E0E0E0; border-radius: 3px; color: #333; }
.star-9 .cell-star { color: #fff; background: #9C27B0; border-radius: 3px; }

/* Direction list */
#direction-list { margin-top: 8px; }
#direction-list h3 { font-size: 14px; margin-bottom: 8px; }
.dir-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 3px;
  font-size: 13px;
}
.dir-daikichi { background: #C8E6C9; }
.dir-chukichi { background: #E8F5E9; }
.dir-kichi { background: #F1F8E9; }
.dir-kyou { background: #FFEBEE; }
.dir-daikyou { background: #FFCDD2; }
.dir-neutral { background: #F5F5F5; }
.dir-name { font-weight: 600; width: 36px; }
.dir-star { width: 80px; }
.dir-label {
  font-weight: 700;
  width: 24px;
  text-align: center;
}
.dir-daikichi .dir-label { color: var(--daikichi); }
.dir-chukichi .dir-label { color: var(--chukichi); }
.dir-kichi .dir-label { color: var(--kichi); }
.dir-kyou .dir-label { color: var(--kyou); }
.dir-daikyou .dir-label { color: var(--daikyou); }
.dir-reasons { font-size: 11px; color: var(--text-light); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
}
.modal-overlay.active { display: block; }
.settings-modal {
  display: none;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 400px;
  max-width: 90vw;
  z-index: 201;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.settings-modal.active { display: block; }
.settings-modal h2 { font-size: 18px; margin-bottom: 16px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.form-group input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.birth-row {
  display: flex;
  gap: 8px;
}
.birth-row input { width: auto; flex: 1; }
.form-hint { display: block; margin-top: 4px; font-size: 11px; color: var(--text-light); }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

/* Ban switcher */
.ban-switcher {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.ban-btn {
  padding: 7px 14px;
  border: none;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.ban-btn:last-child { border-right: none; }
.ban-btn.active {
  background: var(--primary);
  color: #fff;
}
.ban-btn:hover:not(.active) { background: #eee; }

/* Map edge labels */
.main { position: relative; }
#map { position: relative; }

.map-edge-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 5px 8px;
  border-radius: 6px;
  pointer-events: none;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
  min-width: 48px;
  text-align: center;
}
.edge-dir { font-size: 11px; opacity: 0.7; }
.edge-star { font-size: 13px; font-weight: 700; }
.edge-type { font-size: 12px; font-weight: 700; }

.map-edge-daikichi {
  background: rgba(200,230,201,.93);
  color: #1B5E20;
  border: 2px solid var(--daikichi);
}
.map-edge-chukichi {
  background: rgba(232,245,233,.93);
  color: #2E7D32;
  border: 2px solid var(--chukichi);
}
.map-edge-kichi {
  background: rgba(241,248,233,.93);
  color: #558B2F;
  border: 2px solid var(--kichi);
}
.map-edge-kyou {
  background: rgba(255,235,238,.93);
  color: #C62828;
  border: 2px solid var(--kyou);
}
.map-edge-daikyou {
  background: rgba(255,205,210,.93);
  color: #B71C1C;
  border: 2px solid var(--daikyou);
}
.map-edge-neutral {
  background: rgba(245,245,245,.93);
  color: #616161;
  border: 2px solid var(--neutral);
}

/* Sidebar toggle button (スマホ用、PC非表示) */
.sidebar-toggle {
  display: none;
}

/* Sidebar overlay (スマホ用) */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.4);
  z-index: 49;
}
.sidebar-overlay.active { display: block; }

/* Responsive */
@media (max-width: 768px) {
  .container {
    flex-direction: column-reverse;
    height: calc(100vh - 52px);
  }
  .main {
    flex: 1;
    height: auto;
  }
  .sidebar {
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    width: 85vw;
    max-width: 360px;
    height: calc(100vh - 52px);
    min-width: 0;
    border-right: 1px solid var(--border);
    border-bottom: none;
    max-height: none;
    z-index: 50;
    box-shadow: 4px 0 12px rgba(0,0,0,.2);
    overflow-y: auto;
  }
  .sidebar.open {
    display: block;
  }
  .sidebar-toggle {
    display: block;
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 10;
    background: var(--card);
    border: none;
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,.3);
  }
  .sidebar-toggle:hover { background: #eee; }
  .ban-section {
    display: inline-block;
    vertical-align: top;
    width: calc(33% - 8px);
    margin-right: 8px;
  }
  .settings-modal { width: 95vw; }
}

@media (max-width: 480px) {
  .ban-section {
    width: 100%;
    margin-right: 0;
  }
}
