:root {
  --mood-1: #1a1a1a;
  --mood-2: #ef5350;
  --mood-3: #e67e22;
  --mood-4: #f1c40f;
  --mood-5: #58d68d;
  --mood-6: #00bcd4;
  --mood-7: #3498db;
  --dot-color: #ccc;
  --bg-color: #fafafa;
  --text-color: #333;
  --cell-gap: 2px;
  --label-width: 24px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  background-image: radial-gradient(circle, var(--dot-color) 1px, transparent 1px);
  background-size: 20px 20px;
  min-height: 100vh;
  padding: 2rem;
  color: var(--text-color);
}

.container {
  max-width: 1400px;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.edit-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--text-color);
  background: white;
  cursor: pointer;
  font-size: 0.875rem;
  border-radius: 4px;
}

.edit-btn:hover { background: #f0f0f0; }
.edit-btn.active { background: var(--mood-4); color: white; border-color: var(--mood-4); }

.main {
  display: flex;
  gap: 3rem;
  flex-wrap: wrap;
}

.grid-container { flex: 1; }

.header-labels {
  display: grid;
  margin-bottom: var(--cell-gap);
}

.header-labels.horizontal {
  grid-template-columns: var(--label-width) repeat(31, 1fr);
}

.header-labels.vertical {
  grid-template-columns: var(--label-width) repeat(12, 1fr);
}

.header-label {
  text-align: center;
  font-size: 0.625rem;
  font-weight: 500;
}

.grid {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
}

.row {
  display: grid;
  gap: var(--cell-gap);
}

.row.horizontal {
  grid-template-columns: var(--label-width) repeat(31, 1fr);
}

.row.vertical {
  grid-template-columns: var(--label-width) repeat(12, 1fr);
}

.row-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 500;
}

.cell {
  aspect-ratio: 1;
  border: 1px solid #ddd;
  background: white;
  border-radius: 2px;
  position: relative;
}

.cell.disabled {
  background: #eee;
  border-color: #e0e0e0;
}

.cell.today {
  box-shadow: inset 0 0 0 2px rgba(35, 45, 55, 0.45);
}

.cell.selected {
  outline: 3px solid #333;
  outline-offset: -1px;
  clip-path: none !important;
  box-shadow: inset 0 0 0 2px rgba(35, 45, 55, 0.45);
  z-index: 2;
}

.cell.editable { cursor: pointer; }
.cell.editable:hover { opacity: 0.8; }

.cell[data-mood="1"] { background: var(--mood-1); border-color: var(--mood-1); }
.cell[data-mood="2"] { background: var(--mood-2); border-color: var(--mood-2); }
.cell[data-mood="3"] { background: var(--mood-3); border-color: var(--mood-3); }
.cell[data-mood="4"] { background: var(--mood-4); border-color: var(--mood-4); }
.cell[data-mood="5"] { background: var(--mood-5); border-color: var(--mood-5); }
.cell[data-mood="6"] { background: var(--mood-6); border-color: var(--mood-6); }
.cell[data-mood="7"] { background: var(--mood-7); border-color: var(--mood-7); }

.key {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.key h2 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.key-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.key-swatch {
  width: 16px;
  height: 16px;
  border-radius: 2px;
}

.picker {
  position: fixed;
  background: white;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 8px;
  display: none;
  flex-direction: row;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
}

.picker.visible { display: flex; }

.picker-option {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
}

.picker-option:hover { border-color: #333; }
.picker-option.clear { background: white; border: 2px solid #ccc; position: relative; }
.picker-option.clear::after {
  content: "×";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 18px;
}

.cell.has-note::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' stroke='%23333' stroke-width='1' d='M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.cell.weekend,
.cell.holiday,
.cell.leave {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 65% 100%, 50% 80%, 35% 100%, 0 100%);
}

.note-popover {
  position: fixed;
  background: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 12px;
  display: none;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
  width: 200px;
}

.note-popover.visible { display: flex; }

.note-popover textarea {
  width: 100%;
  height: 80px;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px;
  font-family: inherit;
  font-size: 0.875rem;
  resize: none;
}

.note-popover .char-count {
  font-size: 0.75rem;
  color: #999;
  text-align: right;
}

.note-popover .char-count.over { color: var(--mood-2); }

.note-popover .buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.note-popover .leave-btn,
.note-popover .marker-btn {
  background: white;
  border: 1px solid #ccc;
}

.note-popover .leave-btn {
  margin-right: auto;
}

.note-popover .leave-btn.active {
  background: var(--mood-5);
  color: white;
  border-color: var(--mood-5);
}

.note-popover .marker-btn,
.marker-popover .marker-option {
  min-height: 48px;
}

.note-popover .marker-btn.active,
.marker-popover .marker-option.active {
  background: #333;
  color: white;
}

.note-popover button {
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
}

.note-popover .save-btn {
  background: var(--mood-5);
  color: white;
  border: none;
}

.note-popover .cancel-btn {
  background: white;
  border: 1px solid #ccc;
}


.marker-popover {
  position: fixed;
  display: none;
  background: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 101;
}

.marker-popover.visible {
  display: block;
}

.marker-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
}

.details-popover {
  position: fixed;
  display: none;
  background: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
  max-width: 240px;
  font-size: 0.875rem;
}

.details-popover.visible { display: block; }
.details-section + .details-section { margin-top: 0.75rem; }
.details-title { font-weight: 600; margin-bottom: 0.25rem; }
.details-empty { color: #777; }

.note-bubble {
  position: fixed;
  background: #333;
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  display: none;
  max-width: 220px;
  font-size: 0.875rem;
  line-height: 1.4;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 100;
}

.note-bubble.visible { display: block; }

.note-bubble::after {
  content: "";
  position: absolute;
  top: -6px;
  left: 20px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #333;
}

.hidden { display: none !important; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.view-card {
  max-width: 420px;
  margin: 4rem auto;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 1.5rem;
}

.view-card h1,
.view-card p {
  margin-bottom: 1rem;
}

.view-card form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.view-card input {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.view-card button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--text-color);
  border-radius: 4px;
  background: white;
  cursor: pointer;
}

.form-error {
  color: #b00020;
  font-size: 0.875rem;
  min-height: 1.2em;
}

.settings-link {
  color: inherit;
  font-size: 0.875rem;
}

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--mood-1);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  display: none;
}

.toast.visible { display: block; }

@media (max-width: 768px) {
  .cell.has-note::after {
    width: 6px;
    height: 6px;
    top: 0;
    right: 0;
  }

  .cell.weekend,
  .cell.holiday,
  .cell.leave {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 65% 100%, 50% 80%, 35% 100%, 0 100%);
  }
}
