:root {
  --bg: #f0f4f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #3b82f6;
  --accent: #7c3aed;
  --border: rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --radius-lg: 20px;
  --shadow: 0 20px 40px rgba(15, 23, 42, 0.12);
  --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 5px 15px rgba(15, 23, 42, 0.06);
  --transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOutLeft {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-20px);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

body {
  padding: 10%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  background: linear-gradient(135deg, var(--bg) 0%, #f9fafb 100%);
  color: var(--text);
  min-height: 100vh;
  transition: var(--transition);
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem;
}

h1 {
  font-size: clamp(2rem, 3.5vw, 2.75rem);
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: fadeIn 0.6s ease-out;
}

h2 {
  font-weight: 600;
  font-size: 1.5rem;
  margin: 1.5rem 0 1rem;
  animation: fadeIn 0.5s ease-out;
}

h3 {
  font-weight: 500;
  font-size: 1.1rem;
  color: var(--text);
  margin: 1rem 0 0.5rem;
}

p {
  margin: 0 0 1.75rem;
  color: var(--muted);
  line-height: 1.6;
  animation: fadeIn 0.8s ease-out;
}

button {
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.2);
  transition: left 0.35s ease;
  z-index: -1;
}

button:hover::before {
  left: 100%;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 35px rgba(37, 99, 235, 0.3);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 5px 15px rgba(37, 99, 235, 0.2);
}

input {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  font-size: 0.95rem;
  background: var(--card);
  color: var(--text);
  transition: var(--transition);
  width: 100%;
  font-family: inherit;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  transform: translateY(-1px);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

section {
  margin-bottom: 2rem;
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.5s ease-out;
  transition: var(--transition);
}

section:hover {
  box-shadow: var(--shadow-md);
}

#theme-settings {
  display: none;
  animation: fadeIn 0.5s ease-out;
}

.form-row {
  margin-bottom: 1.25rem;
  animation: fadeIn 0.5s ease-out;
}

.form-row label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.form-row small {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.auth-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  animation: slideInRight 0.4s ease-out;
}

#userNickname {
  font-weight: 600;
  color: var(--primary);
  padding: 0.5rem 1rem;
  background: rgba(37, 99, 235, 0.1);
  border-radius: var(--radius);
  white-space: nowrap;
}

ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

li {
  padding: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fafbfc;
  margin-bottom: 0.75rem;
  transition: var(--transition);
  animation: fadeIn 0.4s ease-out;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

li:hover {
  background: var(--card);
  border-color: var(--primary);
  transform: translateX(4px);
  box-shadow: var(--shadow-sm);
}

.status {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  font-weight: 500;
  animation: fadeIn 0.3s ease-out;
  min-height: 20px;
}

.join {
  margin-top: 2rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.05) 0%, rgba(124, 58, 237, 0.05) 100%);
  border-radius: var(--radius);
  border: 2px solid var(--border);
}

.session-view .auth,
.session-view .create-session,
.session-view .user-data {
  display: none;
  animation: slideOutLeft 0.3s ease-out;
}

.session-view #session-details {
  display: block;
  animation: slideInRight 0.4s ease-out;
}

#session-details {
  animation: fadeIn 0.5s ease-out;
}

#sessionInfo {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.05) 0%, rgba(124, 58, 237, 0.05) 100%);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 1rem 0;
  font-size: 1.1rem;
  line-height: 1.8;
}

#sessionInfo strong {
  color: var(--primary);
  font-size: 1.3rem;
}

.session-calendar-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.session-calendar-controls button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
  color: var(--primary);
  font-weight: 700;
}

.session-calendar-controls span {
  font-weight: 600;
  color: var(--text);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(36px, 1fr));
  gap: 8px;
  margin-bottom: 1rem;
}

.day-header {
  background: #f0f4f9;
  color: var(--text);
  font-weight: 600;
  text-align: center;
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 0.8rem;
  min-height: auto;
}

.calendar-square {
  background: #f8fbff;
  min-height: 76px;
  border-radius: 10px;
  border: 1px solid #dbe9ff;
  padding: 6px;
  position: relative;
  cursor: pointer;
  transition: var(--transition);
}

.calendar-square:hover {
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.2);
  transform: translateY(-1px);
}

.calendar-square.empty {
  background: transparent;
  border: none;
  cursor: default;
}

.day-number {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
}

.mobile-day-name {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  opacity: 0.8;
}

.calendar-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  right: 6px;
  font-size: 0.74rem;
  line-height: 1;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(124, 58, 237, 0.1));
  border-radius: 8px;
  padding: 0.25rem;
  color: var(--primary);
  text-align: center;
}

.day-plans {
  font-size: 0.7rem;
  color: var(--text);
  margin-top: 4px;
}

.day-plans div {
  margin-bottom: 2px;
}

.event-count-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  text-align: center;
  margin-top: 0.5rem;
  display: inline-block;
}

.optimal-day {
  background: linear-gradient(135deg, #ffeb3b, #ffc107);
  border-color: #ff9800;
}

.event-form {
  display: grid;
  gap: 0.6rem;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.95);
}

.event-form input {
  border: 1px solid var(--border);
}

.event-form button {
  width: fit-content;
  margin-right: 0.5rem;
}

.auto-next-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  margin-top: 0.5rem;
}

.auto-next-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.calendar {
  background: linear-gradient(145deg, rgba(37, 99, 235, 0.05), rgba(124, 58, 237, 0.05));
  border: 1px solid rgba(37, 99, 235, 0.12);
  padding: 1.75rem;
  border-radius: var(--radius-lg);
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.calendar h2 {
  margin-top: 0;
  color: var(--primary);
}

.calendar .hint {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.calendar-form {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(145px, 1fr) minmax(145px, 1fr) minmax(145px, 1fr) 2fr auto;
  align-items: center;
  margin-bottom: 1rem;
}

.calendar-form input,
.calendar-form button {
  min-height: 44px;
}

.calendar-list-wrapper {
  max-height: 320px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.calendar-table {
  width: 100%;
  border-collapse: collapse;
}

.calendar-table th,
.calendar-table td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.calendar-table tr:last-child td {
  border-bottom: none;
}

.cal-actions button {
  margin-left: 0.25rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 10px;
}

@media (max-width: 680px) {
  body {
    padding: 5%;
  }

  section {
    padding: 1.5rem;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  button {
    width: 100%;
    padding: 0.875rem 1rem;
  }

  input {
    font-size: 16px;
  }

  li {
    flex-direction: column;
    align-items: flex-start;
  }

  .auth-controls {
    flex-direction: column;
    width: 100%;
    gap: 0.75rem;
  }

  .auth-controls button {
    width: 100%;
  }

  #userNickname {
    width: 100%;
    text-align: center;
  }

  .join {
    margin-top: 1.5rem;
  }

  .join input {
    margin-bottom: 0.75rem;
  }

  .calendar-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .day-header {
    display: none;
  }

  .calendar-square {
    min-height: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    text-align: center;
  }

  .calendar-square.empty {
    display: none;
  }

  .day-number {
    font-size: 1.1rem;
  }

  .event-count-badge {
    font-size: 0.8rem;
    margin-top: 0.5rem;
  }
}
