:root {
  --bg-top: #f8f9ff;
  --bg-bottom: #e7ebf4;
  --card: rgba(255, 255, 255, 0.72);
  --card-strong: rgba(255, 255, 255, 0.9);
  --card-muted: rgba(245, 246, 250, 0.82);
  --line: rgba(15, 23, 42, 0.08);
  --text: #111827;
  --muted: #6b7280;
  --blue: #0a84ff;
  --blue-soft: rgba(10, 132, 255, 0.12);
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff453a;
  --shadow: 0 24px 64px rgba(15, 23, 42, 0.14);
  --shadow-soft: 0 14px 32px rgba(15, 23, 42, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(circle at top left, rgba(128, 196, 255, 0.26), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.8), transparent 22%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text);
  font-family:
    "SF Pro Rounded",
    "SF Pro Display",
    ui-rounded,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    sans-serif;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 14px)
    calc(env(safe-area-inset-right) + 14px)
    calc(env(safe-area-inset-bottom) + 26px)
    calc(env(safe-area-inset-left) + 14px);
}

.ios-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(245, 247, 252, 0.72)),
    var(--card);
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(150%);
}

.app-header {
  padding: 16px 18px;
}

.app-header__eyebrow,
.picker-dialog__eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.app-header__title {
  margin: 0;
  font-size: clamp(1.5rem, 6vw, 2.4rem);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.app-header__admin {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.app-header__utility {
  margin-top: 14px;
}

.app-header__utility .action-button {
  min-width: min(100%, 220px);
}

.admin-mode {
  min-width: 0;
}

.admin-mode__badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.08);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.admin-mode__badge.is-admin {
  background: rgba(52, 199, 89, 0.14);
  color: #1b7f3b;
}

.admin-mode__hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.admin-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(245, 249, 255, 0.96), rgba(236, 242, 250, 0.92));
}

.admin-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.admin-panel__eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.admin-panel__title {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.admin-panel__summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

.admin-panel__count {
  color: var(--blue);
  font-size: 1rem;
}

.admin-panel__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.9fr);
  gap: 16px;
  margin-top: 14px;
}

.admin-panel__actions {
  margin-top: 0;
}

.admin-panel__side {
  display: grid;
  gap: 16px;
}

.admin-panel__pending {
  padding: 14px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
}

.admin-panel__pending-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-panel__pending-title {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.3;
}

.admin-panel__empty {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.pending-student-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pending-student-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(10, 132, 255, 0.1);
  color: #0957a5;
  font-size: 0.85rem;
  font-weight: 700;
}

.admin-panel__rules {
  padding: 14px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
}

.admin-panel__helper {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.admin-panel__field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.admin-panel__field-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.admin-panel__select {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font: inherit;
}

.admin-panel__select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.admin-panel__select:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.22);
  outline-offset: 2px;
}

.adjacency-direction-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.adjacency-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.adjacency-field.is-unavailable {
  opacity: 0.72;
}

.adjacency-field__label {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}

.admin-panel__clear-button {
  margin-top: 14px;
  width: 100%;
}

.app-header__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.action-button,
.picker-dialog__close,
.seat-card__lock {
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.action-button:hover,
.action-button:focus-visible,
.picker-dialog__close:hover,
.picker-dialog__close:focus-visible,
.seat-card__main:hover,
.seat-card__main:focus-visible,
.student-option:hover,
.student-option:focus-visible,
.seat-card__lock:hover,
.seat-card__lock:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.12);
}

.action-button:focus-visible,
.picker-dialog__close:focus-visible,
.seat-card__main:focus-visible,
.student-option:focus-visible,
.seat-card__lock:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.22);
  outline-offset: 2px;
}

.action-button {
  min-height: 48px;
  padding: 12px 16px;
  font-size: 0.94rem;
  font-weight: 700;
}

.action-button--primary {
  background: linear-gradient(180deg, #3b9dff, #0a84ff);
  border-color: transparent;
  color: #ffffff;
}

.action-button--secondary {
  background: rgba(17, 24, 39, 0.08);
  color: #1f2937;
}

.action-button--danger {
  background: rgba(255, 69, 58, 0.12);
  color: #a3221b;
}

.action-button--accent {
  background: linear-gradient(180deg, #4dcf8b, #34c759);
  border-color: transparent;
  color: #ffffff;
}

.action-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.workspace {
  margin-top: 12px;
  min-width: 0;
}

.board-panel {
  padding: 14px;
  min-width: 0;
}

.board-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.teacher-desk {
  min-width: min(42vw, 220px);
  padding: 14px 18px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(231, 236, 244, 0.96), rgba(215, 223, 236, 0.88));
  color: #1f2937;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.04em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.board-panel__front {
  margin: 0;
  color: var(--blue);
  font-weight: 700;
  letter-spacing: 0.08em;
}

.seat-board-wrap {
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
}

.seat-board {
  display: grid;
  width: 100%;
  max-width: 100%;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(54px, auto));
  gap: clamp(5px, 1.3vw, 10px);
}

.seat-card {
  position: relative;
  grid-column: var(--seat-col);
  grid-row: var(--seat-row);
  min-height: clamp(54px, 10vw, 72px);
  min-width: 0;
}

.seat-card__main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100%;
  min-width: 0;
  padding: clamp(6px, 1.4vw, 10px);
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(241, 245, 251, 0.88));
  box-shadow: var(--shadow-soft);
  text-align: center;
}

.seat-card__name {
  margin: 0;
  min-height: 0;
  font-size: clamp(0.6rem, 1.95vw, 0.92rem);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.01em;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.seat-card__lock {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 42px;
  padding: 3px 7px;
  color: var(--blue);
  font-size: clamp(0.5rem, 1.55vw, 0.62rem);
  font-weight: 700;
}

.seat-card__lock.is-unlocked {
  color: var(--orange);
  background: rgba(255, 159, 10, 0.16);
}

.seat-card.is-empty .seat-card__main {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(241, 245, 249, 0.78)),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 10px,
      rgba(10, 132, 255, 0.04) 10px,
      rgba(10, 132, 255, 0.04) 20px
    );
  border-style: dashed;
}

.seat-card.is-empty .seat-card__name {
  color: var(--muted);
}

.seat-card.is-locked .seat-card__main {
  border-color: rgba(10, 132, 255, 0.22);
}

.picker-dialog {
  width: min(940px, calc(100vw - 18px));
  max-height: min(90vh, 920px);
  padding: 0;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(241, 245, 251, 0.96));
  box-shadow: 0 30px 90px rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(22px);
}

.picker-dialog::backdrop {
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(12px);
}

.picker-dialog__header,
.picker-dialog__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
}

.picker-dialog__title {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.picker-dialog__current {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.65;
}

.picker-dialog__close {
  min-height: 44px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 700;
}

.admin-dialog {
  width: min(440px, calc(100vw - 18px));
}

.admin-form__body {
  padding: 0 20px 20px;
}

.admin-form__label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.admin-form__input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
}

.admin-form__input:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.22);
  outline-offset: 2px;
}

.admin-form__error {
  margin: 10px 0 0;
  color: #a3221b;
  font-size: 0.86rem;
  font-weight: 700;
}

.student-list {
  display: grid;
  gap: 10px;
  max-height: 56vh;
  padding: 0 20px 10px;
  overflow: auto;
}

.student-option {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  text-align: center;
}

.student-option.is-current {
  border-color: rgba(10, 132, 255, 0.32);
  background: rgba(10, 132, 255, 0.1);
}

.student-option.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.student-option__name {
  font-size: 0.94rem;
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  z-index: 30;
  min-width: min(84vw, 320px);
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.84);
  color: #ffffff;
  font-size: 0.88rem;
  text-align: center;
  transform: translateX(-50%) translateY(14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (min-width: 760px) {
  .student-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .app-header {
    padding: 18px 20px;
  }

  .admin-panel__actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .board-panel {
    padding: 16px;
  }

  .seat-board {
    grid-template-rows: repeat(8, minmax(62px, auto));
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding:
      calc(env(safe-area-inset-top) + 8px)
      calc(env(safe-area-inset-right) + 8px)
      calc(env(safe-area-inset-bottom) + 18px)
      calc(env(safe-area-inset-left) + 8px);
  }

  .ios-card {
    border-radius: 26px;
  }

  .app-header,
  .board-panel {
    padding: 12px;
  }

  .app-header__admin {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header__utility .action-button {
    width: 100%;
  }

  .app-header__actions {
    grid-template-columns: 1fr;
  }

  .admin-panel {
    padding: 14px;
  }

  .admin-panel__header {
    flex-direction: column;
  }

  .admin-panel__grid {
    grid-template-columns: 1fr;
  }

  .board-panel__header {
    align-items: flex-start;
    flex-direction: column;
  }

  .teacher-desk {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    font-size: 0.88rem;
  }

  .seat-board-wrap {
    overflow: hidden;
  }

  .seat-board {
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(48px, auto));
    gap: 3px;
  }

  .seat-card__main {
    border-radius: 14px;
    padding: 6px 3px;
  }

  .seat-card__name {
    font-size: 0.68rem;
    line-height: 1.1;
  }

  .seat-card__lock {
    top: 3px;
    right: 3px;
    min-width: 30px;
    padding: 1px 4px;
    font-size: 0.48rem;
  }

  .picker-dialog {
    inset: auto 0 0 0;
    width: 100vw;
    max-width: none;
    max-height: 88vh;
    margin: 0;
    border-radius: 28px 28px 0 0;
  }

  .picker-dialog__header,
  .picker-dialog__footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-panel__pending {
    padding: 12px;
  }

  .admin-panel__rules {
    padding: 12px;
  }

  .adjacency-direction-grid {
    grid-template-columns: 1fr;
  }

  .admin-form__body {
    padding: 0 16px 16px;
  }

  .student-list {
    max-height: 48vh;
    padding: 0 16px 10px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding:
      calc(env(safe-area-inset-top) + 6px)
      calc(env(safe-area-inset-right) + 6px)
      calc(env(safe-area-inset-bottom) + 16px)
      calc(env(safe-area-inset-left) + 6px);
  }

  .app-header,
  .board-panel {
    padding: 10px;
  }

  .board-panel__header {
    gap: 8px;
    margin-bottom: 8px;
  }

  .teacher-desk {
    padding: 8px 10px;
    border-radius: 18px;
    font-size: 0.82rem;
  }

  .seat-board {
    grid-template-rows: repeat(8, minmax(44px, auto));
    gap: 2px;
  }

  .seat-card__main {
    padding: 5px 2px;
    border-radius: 12px;
  }

  .seat-card__name {
    font-size: 0.62rem;
  }

  .seat-card__lock {
    min-width: 28px;
    font-size: 0.44rem;
  }
}
