:root {
  color-scheme: light;
  font-family: "M PLUS 1p", sans-serif;
  color: #253047;
  background: #eef1f8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100vh; overflow: hidden; background: #eef1f8; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-header {
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #fff;
  border-bottom: 1px solid #e1e5ee;
  position: relative;
  z-index: 5;
}
.app-header > div:first-child { display: flex; align-items: baseline; gap: 12px; }
.app-header h1 { margin: 0; font-size: 18px; font-weight: 900; color: #6d5bd0; }
.app-header h1 span { color: #ef6f9b; }
.app-header small { color: #97a0b3; }
.header-actions { display: flex; gap: 8px; }
.server-status { align-self: center; padding: 5px 8px; border-radius: 999px; background: #eef0f5; color: #667085; font-size: 10px; font-weight: 700; }
.server-status[data-state="connected"] { background: #dcfce7; color: #16734a; }
.server-status[data-state="connecting"] { background: #fef3c7; color: #96620a; }
.server-status[data-state="conflict"], .server-status[data-state="fallback"] { background: #fee2e2; color: #ad3443; }
button {
  border: 1px solid #d9deea;
  border-radius: 9px;
  background: #fff;
  color: #46516a;
  padding: 8px 12px;
}
button:hover { background: #f4f1ff; }
button.primary { color: #fff; border: 0; background: linear-gradient(135deg, #765fdb, #ea6c9c); font-weight: 700; }

.app-body { height: calc(100vh - 64px); display: flex; min-height: 0; }
.control-panel {
  width: 360px;
  flex: 0 0 360px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 16px;
  background: #fff;
  border-right: 1px solid #e1e5ee;
}
.settings-tabs {
  position: sticky;
  top: -16px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  margin: -16px -16px 16px;
  padding: 12px 10px 10px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid #e5e8f0;
  backdrop-filter: blur(8px);
}
.settings-tabs button { min-width: 0; padding: 8px 3px; font-size: 10px; }
.settings-tabs button.is-active { color: #fff; border-color: #765fdb; background: #765fdb; font-weight: 700; }
.settings-panel > section:last-child { margin-bottom: 0; border-bottom: 0; }
.control-panel section { padding: 4px 0 18px; margin-bottom: 16px; border-bottom: 1px solid #edf0f5; }
.control-panel h2 { margin: 0 0 10px; font-size: 14px; }
.control-panel h3 { margin: 12px 0 8px; font-size: 12px; color: #69738a; }
.control-panel label { display: grid; gap: 5px; margin: 9px 0; font-size: 11px; font-weight: 700; color: #687188; }
.control-panel input:not([type="range"]):not([type="checkbox"]), .control-panel select {
  width: 100%; min-width: 0; padding: 8px; border: 1px solid #d8deea; border-radius: 8px; background: #fff; color: #303a50;
}
.control-panel input[type="color"] { height: 38px; padding: 3px; }
.control-panel input[type="range"] { width: 100%; accent-color: #765fdb; }
.range-input-row { display: grid; grid-template-columns: minmax(0, 1fr) 70px; gap: 8px; align-items: center; }
.range-number-input { width: 70px !important; padding: 5px 6px !important; text-align: right; }
.control-panel output { float: right; color: #765fdb; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 8px 0; }
.segmented button { padding: 7px; font-size: 11px; }
.segmented button.is-active { background: #765fdb; color: #fff; border-color: #765fdb; }
.check { display: flex !important; grid-template-columns: auto 1fr; align-items: center; }
.hint { margin: -4px 0 8px; font-size: 10px; color: #9aa2b3; }
.layer-control { padding: 10px; margin: 8px 0; border: 1px solid #e3e7ef; border-radius: 10px; }
.layer-control strong { display: block; margin-bottom: 7px; font-size: 12px; }
.layer-status { margin: 6px 0; min-height: 1.3em; font-size: 10px; color: #8a93a6; overflow-wrap: anywhere; }
.layer-status.needs-file { color: #b36a26; }
.layer-file-row { display: flex; gap: 6px; align-items: center; }
.layer-file-row input { min-width: 0; font-size: 10px; }
.layer-file-row button { padding: 6px 8px; font-size: 10px; }
.panel-button { width: 100%; margin-top: 10px; padding: 7px; font-size: 11px; }
.holiday-data-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.holiday-data-actions .panel-button { margin-top: 0; }
.anniversary-list { display: grid; gap: 6px; margin-top: 10px; }
.anniversary-form-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.anniversary-form-actions .panel-button { margin-top: 0; }
.anniversary-empty { margin: 0; }
.anniversary-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 5px; align-items: center; padding: 7px; border: 1px solid #e3e7ef; border-radius: 8px; }
.anniversary-item strong, .anniversary-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.anniversary-item strong { font-size: 11px; }
.anniversary-item small { color: #8a93a6; font-size: 9px; }
.anniversary-item button { padding: 5px 7px; font-size: 9px; }
.server-asset-button { white-space: nowrap; }

.asset-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(24, 28, 40, .68); }
.asset-modal-card { display: flex; flex-direction: column; width: min(780px, 100%); max-height: 82vh; overflow: hidden; border-radius: 18px; background: #fff; box-shadow: 0 24px 80px rgba(20, 24, 38, .4); }
.asset-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid #e7eaf1; }
.asset-modal-header small { color: #8d7ce0; font-size: 9px; font-weight: 900; letter-spacing: .14em; }
.asset-modal-header h2 { margin: 2px 0 0; font-size: 17px; }
.asset-modal-header button { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 21px; }
.asset-modal-message { margin: 0; padding: 14px 20px 0; color: #7b8498; font-size: 11px; }
.asset-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; overflow-y: auto; padding: 18px 20px 22px; }
.asset-card { min-width: 0; padding: 8px; text-align: left; }
.asset-card img { display: block; width: 100%; aspect-ratio: 1; border-radius: 8px; background: #eef0f5; object-fit: contain; }
.asset-card span { display: block; margin-top: 7px; overflow: hidden; font-size: 10px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }

.preview-area {
  flex: 1;
  min-width: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 26px;
  background: radial-gradient(circle at top right, #e6dceb, transparent 34%), linear-gradient(135deg, #d9d5e7, #d6deea);
}
.preview-stage { position: relative; flex: 0 0 auto; }
.preview-wrapper {
  position: absolute;
  inset: 0 auto auto 0;
  transform-origin: top left;
  outline: 5px solid rgba(72, 65, 94, .72);
  box-shadow: 0 0 0 12px rgba(255, 255, 255, .48), 0 28px 70px rgba(45, 39, 64, .32);
}
.export-canvas { position: relative; overflow: hidden; width: 1920px; height: 1080px; background: linear-gradient(135deg, #ede9fe, #fce7f3 55%, #dbeafe); }
.export-canvas.is-mobile { width: 1080px; height: 1920px; }
.image-layer { position: absolute; left: 50%; top: 50%; width: auto; height: 70%; max-width: none; max-height: none; transform-origin: center; user-select: none; -webkit-user-drag: none; object-fit: contain; }
.image-layer[hidden] { display: none; }
.background-layer { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.image-layer.is-direct-editable { cursor: grab; touch-action: none; }
.image-layer.is-direct-editable.is-dragging { cursor: grabbing; }
#layer-backgroundDecoration { z-index: 2; }
#layer-character { z-index: 20; }
#layer-foregroundDecoration { z-index: 30; }
.safe-area { position: absolute; inset: 5%; z-index: 40; border: 3px dashed rgba(109, 91, 208, .55); pointer-events: none; }
.calendar-group { position: absolute; z-index: 10; display: flex; align-items: stretch; justify-content: center; transform-origin: center; cursor: grab; touch-action: none; }
.calendar-group.is-dragging { cursor: grabbing; }
.calendar-group.is-vertical { flex-direction: column; }
.calendar-month { width: 660px; padding: 26px; overflow: hidden; backdrop-filter: blur(8px); }
.is-mobile .calendar-month { width: 820px; padding: 30px; }
.calendar-month h3 { margin: 0 0 18px; text-align: center; font-family: var(--heading-font); font-size: var(--heading-size); color: var(--heading-color); line-height: 1.15; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-cell { min-width: 0; height: 76px; padding: 7px; border-right: var(--grid-width) solid var(--grid-color); border-bottom: var(--grid-width) solid var(--grid-color); font-family: var(--day-font); font-size: var(--day-size); color: var(--day-color); font-weight: 700; }
.is-mobile .calendar-cell { height: 86px; }
.calendar-cell:nth-child(7n + 1) { border-left: var(--grid-width) solid var(--grid-color); }
.calendar-cell.weekday { height: 40px; padding: 3px; text-align: center; border-top: var(--grid-width) solid var(--grid-color); font-family: var(--weekday-font); font-size: var(--weekday-size); color: var(--weekday-color); }
.calendar-cell.is-sunday { color: var(--sunday-color); }
.calendar-cell.is-saturday { color: var(--saturday-color); }
.calendar-cell.is-holiday { color: var(--holiday-color); }
.calendar-cell.is-holiday-circle > span { display: inline-flex; align-items: center; justify-content: center; width: 1.65em; height: 1.65em; margin: -.22em; border-radius: 50%; color: #fff; background: var(--holiday-color); }
.calendar-cell.is-anniversary-color { color: var(--anniversary-color); }
.calendar-cell.is-anniversary-color.is-holiday-circle > span { box-shadow: 0 0 0 .12em var(--anniversary-color); }
.calendar-cell { position: relative; }
.anniversary-markers { position: absolute; right: .18em; bottom: .08em; display: flex; align-items: flex-end; max-width: 78%; overflow: hidden; font-family: sans-serif; font-size: 1em; line-height: 1; white-space: nowrap; }
.anniversary-marker { display: inline-block; line-height: 1; }
.calendar-cell.is-outside { opacity: var(--outside-opacity); }
.calendar-cell.is-hidden { color: transparent; }
.calendar-cell.is-hidden > span { visibility: hidden; }
.calendar-cell.is-hidden .anniversary-markers { visibility: hidden; }
.status-message { margin: 14px 0 0; font-size: 11px; color: #778197; }

@media (max-width: 900px) {
  .app-header { height: auto; min-height: 64px; align-items: flex-start; flex-direction: column; padding: 12px; }
  .app-header > div:first-child { flex-wrap: wrap; }
  .header-actions { flex-wrap: wrap; }
  .app-body { height: calc(100vh - 116px); }
  .control-panel { width: 310px; flex-basis: 310px; }
}

@media (max-width: 720px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .app-header { position: sticky; top: 0; }
  .app-body { height: auto; min-height: calc(100vh - 116px); flex-direction: column; }
  .control-panel { width: 100%; flex: 0 0 auto; max-height: 48vh; border-right: 0; border-bottom: 1px solid #d4d9e4; }
  .preview-area { min-height: 620px; padding: 22px 16px; }
}
