* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  overflow: hidden;
}

body {
  height: 100vh;
}

#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ============ 위쪽: 방 화면 ============ */
#room {
  position: relative;
  height: 50%;
  overflow: hidden;
  border-bottom: 1px solid #4a3323;
  flex-shrink: 0;
}

.room-bg {
  position: absolute;
  inset: 0;
  background-color: #cfcfcf;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#wander-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.wander-photo {
  position: absolute;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.35));
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-drag: none;
  user-select: none;
  transition: transform 0.15s ease;
}
.wander-photo:active {
  cursor: grabbing;
}
.wander-photo.dragging {
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.45));
  z-index: 50;
}

.photo-message {
  position: absolute;
  transform: translate(-50%, -100%);
  background: #ffffff;
  color: #333;
  padding: 9px 15px;
  border-radius: 14px;
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 220px;
  text-align: center;
  z-index: 60;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  pointer-events: none;
}
.photo-message::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: #ffffff;
}
.photo-message.hidden {
  display: none;
}

/* ============ 사진 우클릭 메뉴 ============ */
.photo-context-menu {
  position: fixed;
  z-index: 200;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.25);
  padding: 12px;
  width: 220px;
}
.photo-context-menu.hidden {
  display: none;
}
.photo-context-menu .popover-row {
  flex-wrap: wrap;
}
.photo-context-menu select {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #ccc;
}
.pcm-actions {
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}
.pcm-actions .btn {
  padding: 3px 9px;
  font-size: 0.7rem;
  border-radius: 6px;
  box-shadow: none;
}

/* ============ 아래쪽: 도구 패널 ============ */
#toolbox {
  position: relative;
  height: 50%;
  background: #fdfaf5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: 20px 16px;
  overflow-y: auto;
}

.settings-gear-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid #4a3323;
  background: #e2e2e2;
  color: #555;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.settings-gear-btn:hover {
  background: #d5d5d5;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  background: #f7f7f7;
  border: 2px solid #4a3323;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.upload-btn:hover {
  background: #eee;
  transform: translateY(-1px);
}
.upload-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.upload-btn.border-black {
  border-color: #000;
}

.panel-row {
  display: flex;
  justify-content: center;
  width: 100%;
}

.side-btn-stack {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.study-panel {
  width: min(94vw, 620px);
  text-align: center;
  border: 1px solid #eee;
  border-radius: 18px;
  padding: 22px 24px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(0,0,0,0.07);
}

.page-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  border: none;
  background: #f0f0f0;
  color: #777;
  padding: 9px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.tab-btn.active {
  background: #2f7ff2;
  color: #fff;
}

.pages-viewport {
  overflow: hidden;
}
.pages-track {
  display: flex;
  width: 200%;
  transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}
.pages-track.show-1 {
  transform: translateX(-50%);
}
.page {
  width: 50%;
  flex-shrink: 0;
  padding: 0 4px;
}

.study-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.study-header h2, .page-pomodoro h2 {
  margin: 0;
  color: #333;
  font-size: 1.3rem;
}

.header-side {
  position: absolute;
  display: flex;
  gap: 6px;
}
.header-left {
  left: 0;
}
.header-right {
  right: 0;
}

.icon-btn {
  border: none;
  background: #f0f0f0;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
}
.icon-btn:hover {
  background: #e4e4e4;
}
.icon-btn-edit {
  padding: 4px 8px;
  font-size: 0.75rem;
  color: #999;
  background: transparent;
}
.icon-btn-edit:hover {
  background: #eee;
}

.popover {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  padding: 12px;
  z-index: 40;
  width: 200px;
  text-align: left;
}
.popover.hidden {
  display: none;
}
.popover-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.85rem;
}
.btn-sm {
  padding: 4px 10px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.stopwatch-display {
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #222;
  margin: 10px 0 18px;
  letter-spacing: 1px;
}

.stopwatch-controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.pomodoro-desc {
  color: #777;
  margin-top: -6px;
}

.pomodoro-phase {
  font-size: 1.2rem;
  font-weight: 700;
  color: #d9822b;
  margin-top: 14px;
}

.pomodoro-display {
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 8px 0;
}

.pomodoro-cycle {
  color: #888;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.pomodoro-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============ 버튼 공통 ============ */
.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 26px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
  filter: brightness(0.96);
}
.btn-lg {
  padding: 16px 30px;
  font-size: 1.1rem;
}

.btn-blue {
  background: #2f7ff2;
  color: #fff;
}
.btn-blue.active {
  background: #1d4fa3;
}

.btn-yellow {
  background: #ffcb3d;
  color: #4a3323;
}

.btn-green {
  background: #3cb371;
  color: #fff;
}

.btn-gray {
  background: #e2e2e2;
  color: #444;
}

.btn-purple {
  background: #8b5cf6;
  color: #fff;
}

/* ============ 모달 공통 ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden {
  display: none;
}

.modal {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 28px 32px;
  width: min(92vw, 520px);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.modal h2 {
  margin-top: 0;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: none;
  background: #f0f0f0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
}
.modal-close:hover {
  background: #e0e0e0;
}

/* ============ 설정 모달 ============ */
.settings-section {
  margin-bottom: 18px;
  text-align: left;
}
.settings-label {
  font-weight: 700;
  font-size: 0.88rem;
  color: #555;
  margin-bottom: 6px;
  display: block;
}
.settings-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.settings-toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  color: #333;
  cursor: pointer;
}
.settings-hint {
  margin: 4px 0 0 24px;
  font-size: 0.78rem;
  color: #999;
}
#speed-slider, #size-slider, #music-volume {
  width: 100%;
}
.settings-row-inline {
  align-items: center;
  margin-top: 8px;
}
.settings-hint-inline {
  font-size: 0.82rem;
  color: #777;
  white-space: nowrap;
}
.bg-size-input {
  width: 80px;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.85rem;
}
#toolbox-color-input {
  width: 48px;
  height: 38px;
  padding: 2px;
  border: 1px solid #ccc;
  border-radius: 8px;
  cursor: pointer;
  background: none;
}

/* ============ 기록 모달 ============ */
.history-list-wrap {
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 10px;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.history-table th, .history-table td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}
.history-delete-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: #bbb;
  font-size: 1rem;
}
.history-delete-btn:hover {
  color: #e63946;
}

/* ============ 달력 모달 ============ */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
}
.cal-month-label {
  font-weight: 700;
  min-width: 100px;
  text-align: center;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: #999;
  font-size: 0.78rem;
  margin-bottom: 4px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendar-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f2f2f2;
  color: #333;
}
.calendar-cell.empty {
  visibility: hidden;
  cursor: default;
}
.calendar-cell.selected {
  outline: 3px solid #2f7ff2;
  outline-offset: -3px;
}
.calendar-detail {
  text-align: center;
  color: #555;
  margin-top: 12px;
  font-size: 0.88rem;
}

/* ============ 응원 멘트 편집 ============ */
.message-edit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  margin-bottom: 14px;
}
.message-edit-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.message-edit-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.9rem;
}
.message-edit-row button {
  border: none;
  background: none;
  cursor: pointer;
  color: #bbb;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.message-edit-row button:hover {
  color: #e63946;
}
.message-editor-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ============ 체크리스트 사이드 패널 (밀림 형식) ============ */
.side-panel {
  flex: 0 0 auto;
  width: 0;
  overflow: hidden;
  background: #fff;
  box-shadow: -6px 0 20px rgba(0,0,0,0.12);
  transition: width 0.28s ease;
  height: 100vh;
}
.side-panel.open {
  width: min(92vw, 420px);
}
.side-panel-inner {
  position: relative;
  width: min(92vw, 420px);
  height: 100%;
  padding: 24px 22px;
  overflow-y: auto;
  box-sizing: border-box;
}

.todo-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #eee;
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: #555;
  gap: 4px;
}

.form-row input,
.form-row select {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 0.95rem;
}

.todo-add-btn {
  align-self: flex-end;
  margin-top: 4px;
}

.todo-sort-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: #555;
}
.todo-sort-row select {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.todo-list-wrap {
  overflow-x: auto;
}

.todo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.todo-table th, .todo-table td {
  padding: 8px 5px;
  text-align: center;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}

.todo-table td.content-cell {
  white-space: normal;
  text-align: left;
  max-width: 140px;
}

.todo-table tr.done td {
  color: #aaa;
  text-decoration: line-through;
}

.importance-상 { color: #e63946; font-weight: 700; }
.importance-중 { color: #d9822b; font-weight: 700; }
.importance-하 { color: #3cb371; font-weight: 700; }

.duration-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
}
.todo-duration-input {
  width: 40px;
  padding: 4px 4px;
  border: 1px solid #ccc;
  border-radius: 6px;
  text-align: center;
  font-size: 0.8rem;
}
.todo-duration-input.no-spin::-webkit-inner-spin-button,
.todo-duration-input.no-spin::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.todo-duration-input.no-spin {
  -moz-appearance: textfield;
}
.todo-duration-input:disabled {
  background: #f4f4f4;
  color: #bbb;
  border-color: #eee;
}

.todo-delete-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: #bbb;
  font-size: 1rem;
}
.todo-delete-btn:hover {
  color: #e63946;
}

.todo-empty {
  text-align: center;
  color: #999;
  padding: 20px 0;
}

/* ============ 반응형 ============ */
@media (max-width: 600px) {
  .form-row {
    flex-direction: column;
  }
  .panel-row {
    flex-direction: column;
    align-items: center;
  }
  .side-btn-stack {
    position: static;
    flex-direction: row;
    width: 100%;
  }
  .side-btn-stack .btn {
    flex: 1;
  }
  .side-panel.open, .side-panel-inner {
    width: 100vw;
  }
}
