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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Hiragino Sans", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f0f4f8;
}

/* ========== Header ========== */
header {
  background: linear-gradient(135deg, #1a3a5c 0%, #2d6a9f 100%);
  color: white;
  padding: 1.25rem 1rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  min-height: 44px;
  line-height: 44px;
  padding: 0 0.25rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: white;
  text-decoration: underline;
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
}

.subtitle {
  font-size: 0.875rem;
  opacity: 0.85;
  margin-top: 0.3rem;
}

/* ========== Main ========== */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

/* ========== AdSense ========== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ========== Controls ========== */
.controls-section {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  margin-bottom: 1rem;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.control-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 180px;
}

.control-item label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
}

.control-item input[type="date"],
.control-item select {
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  border: 1.5px solid #d0d7de;
  border-radius: 7px;
  background: white;
  color: #333;
  min-height: 44px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.control-item input[type="date"]:focus,
.control-item select:focus {
  outline: none;
  border-color: #2d6a9f;
}

.select-row {
  display: flex;
  gap: 0.5rem;
}

.select-row select {
  flex: 1;
}

.btn-add {
  padding: 0 1.1rem;
  font-size: 0.9rem;
  font-weight: 700;
  background: #2d6a9f;
  color: white;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  min-height: 44px;
  min-width: 60px;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-add:hover {
  background: #1a3a5c;
}

/* ========== City Tags ========== */
.city-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.city-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #e8f0fb;
  color: #1a3a5c;
  border: 1.5px solid #b3ccef;
  border-radius: 20px;
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.city-tag .remove-btn {
  background: none;
  border: none;
  color: #6683a8;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.city-tag .remove-btn:hover {
  background: #c4d8f5;
  color: #1a3a5c;
}

/* ========== Grid Section ========== */
.grid-section {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  margin-bottom: 1rem;
}

.grid-wrapper {
  /* outer wrapper for scroll indicator shadow */
}

.grid-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ========== Time Grid Table ========== */
.time-grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 320px;
  font-size: 0.875rem;
}

.time-grid thead th {
  position: sticky;
  top: 0;
  background: #1a3a5c;
  color: white;
  padding: 0.6rem 0.75rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.15);
  z-index: 2;
}

.time-grid thead th:first-child {
  text-align: left;
  min-width: 60px;
  position: sticky;
  left: 0;
  z-index: 3;
  border-right: 2px solid rgba(255,255,255,0.3);
}

.time-grid thead th .city-name {
  display: block;
  font-size: 0.95rem;
}

.time-grid thead th .tz-offset {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.8;
  margin-top: 0.1rem;
}

.time-grid tbody tr {
  transition: background 0.1s;
}

.time-grid tbody tr:hover td {
  filter: brightness(0.95);
}

.time-grid tbody td {
  padding: 0.35rem 0.75rem;
  text-align: center;
  border-bottom: 1px solid #eef0f3;
  border-right: 1px solid #eef0f3;
  white-space: nowrap;
  transition: background 0.15s;
}

.time-grid tbody td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: #f7f9fc;
  font-weight: 700;
  color: #4a5568;
  font-size: 0.8rem;
  border-right: 2px solid #dde3eb;
  z-index: 1;
  min-width: 60px;
}

/* Cell states */
.cell-off {
  background: #f7f9fc;
  color: #aab0bb;
  font-size: 0.8rem;
}

.cell-work {
  background: #e6f7ee;
  color: #276843;
  font-weight: 600;
  font-size: 0.85rem;
}

.cell-recommended {
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Current hour highlight */
.cell-current {
  outline: 2px solid #f59e0b;
  outline-offset: -2px;
}

.cell-time-label {
  font-size: 0.8rem;
  color: #64748b;
}

/* ========== Legend ========== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-top: 0.875rem;
  font-size: 0.8rem;
  color: #555;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.dot-work {
  background: #e6f7ee;
  border: 1.5px solid #6dbf8c;
}

.dot-recommended {
  background: #dbeafe;
  border: 1.5px solid #60a5fa;
}

.dot-off {
  background: #f7f9fc;
  border: 1.5px solid #d1d9e6;
}

/* ========== Summary Section ========== */
.summary-section {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  margin-bottom: 1rem;
}

.summary-section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1a3a5c;
  margin-bottom: 0.875rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e2e8f0;
}

.summary-placeholder {
  color: #9aa5b4;
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem 0;
}

.summary-overlap {
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.summary-overlap-title {
  font-size: 1rem;
  font-weight: 700;
  color: #1d4ed8;
  margin-bottom: 0.5rem;
}

.summary-overlap-detail {
  font-size: 0.875rem;
  color: #3b5fa8;
  line-height: 1.8;
}

.summary-overlap-detail .city-time-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.summary-overlap-detail .city-time-badge {
  display: inline-flex;
  align-items: center;
  background: white;
  border: 1px solid #bfdbfe;
  border-radius: 5px;
  padding: 0.2rem 0.6rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #1d4ed8;
}

.summary-no-overlap {
  background: #fff7ed;
  border: 1.5px solid #fed7aa;
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.9rem;
  color: #c2410c;
  text-align: center;
}

/* ========== Howto Section ========== */
.howto-section {
  background: white;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  margin-bottom: 1rem;
}

.howto-section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1a3a5c;
  margin-bottom: 0.75rem;
  margin-top: 1.5rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #e2e8f0;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-section ol {
  padding-left: 1.35rem;
  color: #4a5568;
  font-size: 0.9rem;
}

.howto-section li {
  margin-bottom: 0.55rem;
  line-height: 1.65;
}

.howto-section p {
  color: #4a5568;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
  line-height: 1.7;
}

.howto-section code {
  background: #f1f5f9;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: #0f4c81;
}

/* ========== Footer ========== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #888;
}

footer a {
  color: #666;
  text-decoration: underline;
}

footer a:hover {
  color: #333;
}

/* ========== Empty State ========== */
.empty-grid-message {
  text-align: center;
  padding: 2rem 1rem;
  color: #9aa5b4;
  font-size: 0.9rem;
}

/* ========== Responsive ========== */
@media (min-width: 640px) {
  header h1 {
    font-size: 1.7rem;
  }

  main {
    padding: 1.5rem 1.5rem;
  }

  .controls-row {
    flex-wrap: nowrap;
  }

  .control-item {
    min-width: 200px;
  }
}

@media (min-width: 1024px) {
  main {
    padding: 1.5rem 2rem;
  }
}
