:root {
  --bg: #313131;
  --surface: #414141;
  --surface-hover: #1a2235;
  --border: #434343;
  --text: #e6e0e6;
  --text-muted: #8b8b8b;
  --accent: #e4eeff;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --day-bg: rgba(197, 197, 197, 0.08);
  --day-border: rgba(200, 200, 200, 0.25);
  --night-bg: rgb(7, 7, 46, 0.2);
  --night-border: rgba(119, 119, 119, 0.25);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  padding-top: calc(2rem + var(--safe-top));
  padding-bottom: calc(2rem + var(--safe-bottom));
  padding-left: calc(1.25rem + var(--safe-left));
  padding-right: calc(1.25rem + var(--safe-right));
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.25rem 0;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

label {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.875rem;
}

select {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-width: 200px;
  min-height: 44px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8b8b' d='M6 8.825a.5.5 0 0 1-.354-.146l-4-4a.5.5 0 0 1 .708-.708L6 7.617l3.646-3.646a.5.5 0 0 1 .708.708l-4 4A.5.5 0 0 1 6 8.825z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
  transition: border-color 0.15s ease;
}

select:hover, select:focus {
  border-color: var(--accent);
  outline: none;
}

.schedule-wrap {
  position: relative;
  overflow: hidden;
}

#schedule {
  transition: opacity 0.2s ease;
}

.post-block {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.post-block:last-child { border-bottom: none; }

.post-block h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
}

.shift-section {
  margin-bottom: 0.625rem;
}

.shift-section:last-child {
  margin-bottom: 0;
}

.shift-title {
  font-size: 0.9375rem;
  font-weight: 500;
  margin: 0 0 0.375rem 0;
}

.shift-title.day { color: #fffad9; }
.shift-title.night { color: #ced3ff; }

.slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.no-slots {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.slot {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.9375rem;
  font-weight: 700;
  white-space: nowrap;
}

.slot.day {
  background: #ffffff;
  color: #1a1a1a;
}

.slot.night {
  background: #1a1a1a;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.empty, .loading, .error {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

.loading { font-style: italic; }
.error { color: #f87171; }

.swipe-hint {
  display: none;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.75rem 0 0;
  opacity: 0.5;
}

/* Login */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-card h2 {
  margin: 0 0 0.25rem 0;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}

.login-card .login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

.login-card .field {
  margin-bottom: 1rem;
}

.login-card .field label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.login-card input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  min-height: 44px;
  transition: border-color 0.15s;
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card .login-error {
  color: #f87171;
  font-size: 0.8125rem;
  text-align: center;
  min-height: 1.25rem;
  margin-bottom: 0.5rem;
}

.login-card button {
  width: 100%;
  padding: 0.875rem;
  border: none;
  border-radius: var(--radius-sm);
  background: #e4eeff;
  color: #1a1a1a;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: opacity 0.15s, transform 0.1s;
}

.login-card button:hover { opacity: 0.9; }
.login-card button:active { transform: scale(0.98); }
.login-card button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8125rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn-logout:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---- Mobile: <= 640px ---- */

@media (max-width: 640px) {
  .page {
    padding: 1.25rem 0.875rem;
    padding-top: calc(1.25rem + var(--safe-top));
    padding-bottom: calc(1.25rem + var(--safe-bottom));
    padding-left: calc(0.875rem + var(--safe-left));
    padding-right: calc(0.875rem + var(--safe-right));
  }
  header {
    margin-bottom: 1rem;
    flex-wrap: wrap;
  }
  h1 { font-size: 1.4rem; }
  .subtitle { font-size: 0.8125rem; }
  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.375rem;
    margin-bottom: 1.25rem;
  }
  select {
    width: 100%;
    min-width: unset;
    font-size: 1rem;
    padding: 0.875rem 1rem;
    padding-right: 2.5rem;
    min-height: 48px;
    border-radius: var(--radius);
  }
  .post-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem;
    margin-bottom: 0.625rem;
  }
  .post-block:last-child {
    margin-bottom: 0;
    border-bottom: 1px solid var(--border);
  }
  .post-block h2 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
  }
  .shift-title { font-size: 0.875rem; }
  .slots { gap: 0.375rem; }
  .slot {
    font-size: 0.875rem;
    padding: 0.375rem 0.6rem;
  }
  .login-card {
    margin: 0 0.75rem;
    padding: 2rem 1.5rem;
  }
  .login-card h2 { font-size: 1.375rem; }
  .swipe-hint { display: block; }
}

/* ---- Very small screens: <= 380px ---- */

@media (max-width: 380px) {
  .page {
    padding: 1rem 0.5rem;
    padding-top: calc(1rem + var(--safe-top));
    padding-bottom: calc(1rem + var(--safe-bottom));
  }
  h1 { font-size: 1.25rem; }
  .slot {
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
  }
  .login-card {
    margin: 0 0.5rem;
    padding: 1.75rem 1.25rem;
  }
}

/* Touch device feedback */

@media (hover: none) and (pointer: coarse) {
  select:active,
  .btn-logout:active,
  .login-card button:active {
    transform: scale(0.97);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
