:root {
  color-scheme: light;
  --bg: #fffaf5;
  --surface: #ffffff;
  --surface-soft: #fff2e8;
  --text: #3f3732;
  --muted: #81766e;
  --line: #eaded5;
  --primary: #e77e55;
  --primary-strong: #bd5a36;
  --primary-soft: #ffe0d2;
  --accent: #6b9f90;
  --accent-soft: #dcefe9;
  --danger: #b94f4f;
  --shadow: 0 14px 35px rgba(95, 69, 51, 0.09);
  --radius: 22px;
  font-family:
    "Yu Gothic UI", "Hiragino Sans", Meiryo, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="forest"] {
  --bg: #f3f7f0;
  --surface: #ffffff;
  --surface-soft: #e6f0e1;
  --text: #2f4035;
  --muted: #6d7d70;
  --line: #d7e3d5;
  --primary: #628b66;
  --primary-strong: #3f6846;
  --primary-soft: #d8ead8;
  --accent: #b07955;
  --accent-soft: #f2dfd1;
}

[data-theme="night"] {
  color-scheme: dark;
  --bg: #1e2431;
  --surface: #293142;
  --surface-soft: #333d50;
  --text: #f5f1ea;
  --muted: #b9bfca;
  --line: #414c60;
  --primary: #f1a57f;
  --primary-strong: #ffc4a5;
  --primary-soft: #513d3a;
  --accent: #80b8aa;
  --accent-soft: #304d49;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.23);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 5%, var(--primary-soft), transparent 24rem),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
canvas:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 2px;
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand img {
  width: 52px;
  height: 52px;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 1.55rem;
  letter-spacing: 0.04em;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.88rem;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 10px max(18px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
}

.topbar .brand {
  margin: 0;
}

.topbar .brand img {
  width: 42px;
  height: 42px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  box-shadow: 0 0 0 1px var(--line);
}

.avatar canvas {
  width: 100%;
  height: 100%;
}

.layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 28px;
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 26px 0 100px;
}

.sidebar {
  position: sticky;
  top: 98px;
  align-self: start;
  display: grid;
  gap: 8px;
}

.nav-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: var(--surface);
  box-shadow: 0 7px 22px rgba(95, 69, 51, 0.07);
}

.nav-button.active {
  color: var(--primary-strong);
  font-weight: 800;
}

.nav-icon {
  width: 1.35em;
  text-align: center;
}

.main-content {
  min-width: 0;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-heading h2,
.page-heading p {
  margin: 0;
}

.page-heading h2 {
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.page-heading p {
  margin-top: 4px;
  color: var(--muted);
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(290px, 0.85fr);
  gap: 18px;
}

.stack {
  display: grid;
  gap: 18px;
}

.card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card h3,
.card h4,
.card p {
  margin-top: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-header h3,
.card-header p {
  margin: 0;
}

.muted,
.meta {
  color: var(--muted);
}

.meta {
  font-size: 0.85rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.button:hover {
  filter: brightness(0.97);
  transform: translateY(-1px);
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.button.ghost {
  background: transparent;
  color: var(--primary-strong);
}

.button.danger {
  background: var(--danger);
  color: #ffffff;
}

.button.danger:hover {
  filter: brightness(0.9);
}

.button.small {
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.84rem;
}

.tool-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}

.field label,
.field > span {
  font-size: 0.9rem;
  font-weight: 800;
}

.field input,
.field textarea,
.field select,
.chat-form input,
.inline-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  background: var(--bg);
  color: var(--text);
}

.field textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.75;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.check-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  cursor: pointer;
}

.calendar-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.calendar-day {
  position: relative;
  display: grid;
  place-items: start;
  min-height: 66px;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.calendar-day:hover {
  border-color: var(--line);
}

.calendar-day.has-entry {
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 800;
}

.calendar-day.selected {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.calendar-day.outside {
  opacity: 0.26;
}

.calendar-count {
  align-self: end;
  justify-self: end;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.7rem;
  text-align: center;
}

.calendar-people {
  align-self: end;
  width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.66rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diary-list,
.feed-list {
  display: grid;
  gap: 14px;
}

.diary-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
}

.diary-card h4 {
  margin: 7px 0;
  font-size: 1.05rem;
}

.diary-card .diary-body {
  margin: 10px 0;
  line-height: 1.7;
  white-space: pre-wrap;
}

.diary-author {
  display: flex;
  align-items: center;
  gap: 9px;
}

.diary-actions,
.reaction-row,
.toolbar,
.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.drawing-preview {
  display: block;
  width: min(100%, 520px);
  height: auto;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.comment-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.comment {
  padding: 9px 11px;
  border-radius: 12px;
  background: var(--surface-soft);
  font-size: 0.9rem;
}

.comment p {
  margin: 4px 0 0;
}

.inline-form,
.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

.drawing-editor {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #fff;
}

.drawing-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 11px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
}

.tool-button {
  min-height: 35px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}

.tool-button.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 800;
}

.drawing-toolbar input[type="range"] {
  width: 100px;
}

.drawing-toolbar input[type="color"] {
  width: 38px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  touch-action: none;
}

.canvas-wrap.square {
  width: min(100%, 520px);
  aspect-ratio: 1;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.group-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.group-tab {
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.group-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.request-row,
.account-row,
.search-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.request-row:last-child,
.account-row:last-child,
.search-result:last-child {
  border-bottom: 0;
}

.chat-panel {
  display: grid;
  grid-template-rows: minmax(360px, 58vh) auto;
  overflow: hidden;
  padding: 0;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 20px;
}

.message {
  align-self: flex-start;
  max-width: min(78%, 560px);
}

.message.mine {
  align-self: flex-end;
}

.message-bubble {
  padding: 10px 13px;
  border-radius: 16px 16px 16px 5px;
  background: var(--surface-soft);
  line-height: 1.55;
  white-space: pre-wrap;
}

.message.mine .message-bubble {
  border-radius: 16px 16px 5px 16px;
  background: var(--primary-soft);
}

.message-meta {
  margin: 0 5px 4px;
  color: var(--muted);
  font-size: 0.73rem;
}

.chat-form {
  margin: 0;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.theme-choice {
  padding: 16px 10px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
}

.theme-choice.active {
  border-color: var(--primary);
}

.notice,
.error-notice {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.9rem;
}

.error-notice {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  color: var(--danger);
}

.mobile-nav {
  display: none;
}

@media (max-width: 820px) {
  .layout {
    display: block;
    width: min(100% - 24px, 680px);
    padding-top: 18px;
  }

  .sidebar {
    display: none;
  }

  .grid-two {
    grid-template-columns: 1fr;
  }

  .mobile-nav {
    position: fixed;
    z-index: 30;
    right: 10px;
    bottom: 10px;
    left: 10px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
  }

  .mobile-nav .nav-button {
    display: grid;
    justify-items: center;
    gap: 2px;
    padding: 7px 2px;
    font-size: 0.67rem;
    text-align: center;
  }

  .topbar {
    padding-inline: 14px;
  }

  .user-chip > span:not(.avatar) {
    display: none;
  }

  .calendar-day {
    min-height: 55px;
    padding: 5px;
  }
}

@media (max-width: 520px) {
  .login-card,
  .card {
    padding: 16px;
    border-radius: 18px;
  }

  .form-row,
  .theme-grid {
    grid-template-columns: 1fr;
  }

  .page-heading {
    align-items: start;
    flex-direction: column;
  }

  .calendar-grid {
    gap: 2px;
  }

  .calendar-day {
    min-height: 49px;
    border-radius: 9px;
    font-size: 0.78rem;
  }

  .message {
    max-width: 90%;
  }
}
